[PATCH] D15686: PR25910: clang allows two var definitions with the same mangled name

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 4 17:06:57 PST 2016


tra added inline comments.

================
Comment at: lib/CodeGen/CodeGenModule.cpp:1235-1236
@@ -1235,8 +1234,4 @@
     // different type.
-    // FIXME: Support for variables is not implemented yet.
-    if (isa<FunctionDecl>(D.getDecl()))
-      GV = cast<llvm::GlobalValue>(GetAddrOfGlobal(D, /*IsForDefinition=*/true));
-    else
-      if (!GV)
-        GV = GetGlobalValue(getMangledName(D));
+    llvm::GlobalValue *GV =
+        cast<llvm::GlobalValue>(GetAddrOfGlobal(D, /*IsForDefinition=*/true));
 
----------------
andreybokhanko wrote:
> Artem, to address your concern (from http://reviews.llvm.org/rL254195#39417): if IsForDefinition equals to true, it is guaranteed that we get GlobalValue here. We specifically call GetAddrOfGlobal to create (or get) a global with required type, not cast from a declaration with a different type.
Empirical evidence suggests that it's possible to get non GlobalValue from GetAddrOfGlobal.
For instance, you may get llvm::UnaryConstantExpr which would be the case when GetAddrOfGlobal returns an addrspacecast which may happen during CUDA or OpenCL compilation.

If you want to reproduce the problem, apply my pending patch http://reviews.llvm.org/D15305 which has to defer emitting some variables. Run clang tests and you will see a lot of CUDA test cases crashing with assertion on this cast.



http://reviews.llvm.org/D15686





More information about the cfe-commits mailing list