[patch] Make it explicit that nulls are not allowed in names

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Nov 14 05:33:31 PST 2013

>> The object files we support use null terminated strings, so there is
>> no way to support these.
>> This patch adds an assert to catch bad API use and an error check in
>> the .ll parser.
> I think this would be better as part of the IR Verifier than in setName(), but the idea is sensible.

I can move it there, but why? My rule of the thumb has been that
invariants that are only true at the end of pass are checked in the
Verifier. Invariants that are always true are checked on

For example, the GlobalVariable constructor has

 if (InitVal) {
    assert(InitVal->getType() == Ty &&
           "Initializer should be the same type as the GlobalVariable!");

If someone is passing an initializer, they should be able to get the
type right at construction time. On the other hand, the verifier is
the one that checks that if there is no initializer

    Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
            "invalid linkage type for global .declaration", &GV);

The reason being that it is convenient in some cases to create a
variable without an initializer and then set it, so this invariant is
invalid at construction time.


More information about the llvm-commits mailing list