Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Path-aware TBAA produces the same mangled name for internal names #17996

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR17997
Status NEW
Importance P normal
Reported by Reid Kleckner (rnk@google.com)
Reported on 2013-11-19 16:48:34 -0800
Last modified on 2017-08-28 00:28:48 -0700
Version unspecified
Hardware PC Windows NT
CC karnajitw@gmail.com, llvm-bugs@lists.llvm.org, llvm@sunfishcode.online, mren@apple.com, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The non-path-aware TBAA code has this fragment of code:
  if (const EnumType *ETy = dyn_cast<EnumType>(Ty)) {
    // In C++ mode, types have linkage, so we can rely on the ODR and
    // on their mangled names, if they're external.
    // TODO: Is there a way to get a program-wide unique name for a
    // decl with local linkage or no linkage?
    if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
      return MetadataCache[Ty] = getChar();

    SmallString<256> OutName;
    llvm::raw_svector_ostream Out(OutName);
    MContext.mangleTypeName(QualType(ETy, 0), Out);
    Out.flush();
    return MetadataCache[Ty] = createTBAAScalarType(OutName, getChar());
  }

Path-aware TBAA doesn't have any such condition.  Is this a problem?  Do the
names matter?  I don't see any code that combines them in lib/Linker or
lib/LTO.  You can see the issue for this program:

$ cat t.cpp
namespace {
struct Foo {
#ifdef CONFIG_1
  int a;
#endif
  int b;
};
}
int *store1();
#ifdef CONFIG_1
static Foo c;
int *store1() {
  c.b = 42;
  return &c.b;
}
#else
static Foo c;
int *store2() {
  c.b = 43;
  return &c.b;
}
int main() {
  return *store1() + *store2();
}
#endif

$ clang++ -c t.cpp -O1 -emit-llvm -S -o - -DCONFIG_1 | grep ZTS && clang++
t.cpp -c -o t2.bc -O1 -emit-llvm -o - -S | grep _ZTS
!2 = metadata !{metadata !"_ZTSN12_GLOBAL__N_13FooE", metadata !3, i64 0,
metadata !3, i64 4}
!2 = metadata !{metadata !"_ZTSN12_GLOBAL__N_13FooE", metadata !3, i64 0}

They use the same name, "_ZTSN12_GLOBAL__N_13FooE".
Quuxplusone commented 10 years ago

Hi Reid,

Thanks for the example.

The example you gave should not cause any issue, because even though the name is the same, the MDNodes are different.

It may cause problem if we have structs that are mangled to the same name and have the same fields but should be treated differently. I am not sure if such cases exist.

Manman