[clang] 8285522 - [CodeGen] Always update map entry after adding initializer

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 16 07:29:45 PST 2021


Author: Nikita Popov
Date: 2021-12-16T16:29:35+01:00
New Revision: 828552201420720ff52c9a27ea4e8f3697f1abc1

URL: https://github.com/llvm/llvm-project/commit/828552201420720ff52c9a27ea4e8f3697f1abc1
DIFF: https://github.com/llvm/llvm-project/commit/828552201420720ff52c9a27ea4e8f3697f1abc1.diff

LOG: [CodeGen] Always update map entry after adding initializer

With opaque pointers the pointer cast may be a no-op, such that
var and castedAddr are the same. However, we still need to update
the map entry as the underlying global changed. We could explicitly
check whether the global was replaced, but we may as well just
always update the entry.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index f6b758ba30a0..2d1f229108d6 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -405,8 +405,8 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D,
 
   // Store into LocalDeclMap before generating initializer to handle
   // circular references.
-  setAddrOfLocalVar(
-      &D, Address(addr, ConvertTypeForMem(D.getType()), alignment));
+  llvm::Type *elemTy = ConvertTypeForMem(D.getType());
+  setAddrOfLocalVar(&D, Address(addr, elemTy, alignment));
 
   // We can't have a VLA here, but we can have a pointer to a VLA,
   // even though that doesn't really make any sense.
@@ -459,8 +459,7 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D,
   // RAUW's the GV uses of this constant will be invalid.
   llvm::Constant *castedAddr =
     llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
-  if (var != castedAddr)
-    LocalDeclMap.find(&D)->second = Address(castedAddr, alignment);
+  LocalDeclMap.find(&D)->second = Address(castedAddr, elemTy, alignment);
   CGM.setStaticLocalDeclAddress(&D, castedAddr);
 
   CGM.getSanitizerMetadata()->reportGlobalToASan(var, D);


        


More information about the cfe-commits mailing list