[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Thu May 22 05:25:11 PDT 2025


================
@@ -274,9 +274,10 @@ Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V,
 Address CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E) {
   ASTContext &Ctx = CGF.getContext();
   Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
+  const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
                        ? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
-                       : Ptr.getElementType()->getScalarSizeInBits() / 8;
+                       : DL.getTypeSizeInBits(Ptr.getElementType()) / 8;
----------------
arsenm wrote:

```suggestion
                       : DL.getTypeStoreSize(Ptr.getElementType());
```

https://github.com/llvm/llvm-project/pull/141053


More information about the cfe-commits mailing list