[clang] [C2y] Fix _Countof handling of VLAs (PR #141621)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue May 27 08:47:03 PDT 2025
================
@@ -3574,20 +3574,26 @@ ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
CGF.EmitIgnoredExpr(E->getArgumentExpr());
}
- auto VlaSize = CGF.getVLASize(VAT);
- llvm::Value *size = VlaSize.NumElts;
-
// For sizeof and __datasizeof, we need to scale the number of elements
// by the size of the array element type. For _Countof, we just want to
// return the size directly.
+ llvm::Value *Size;
if (Kind != UETT_CountOf) {
+ auto VlaSize = CGF.getVLASize(VAT);
+ Size = VlaSize.NumElts;
+
// Scale the number of non-VLA elements by the non-VLA element size.
CharUnits eltSize = CGF.getContext().getTypeSizeInChars(VlaSize.Type);
if (!eltSize.isOne())
- size = CGF.Builder.CreateNUWMul(CGF.CGM.getSize(eltSize), size);
+ Size = CGF.Builder.CreateNUWMul(CGF.CGM.getSize(eltSize), Size);
----------------
AaronBallman wrote:
I made the changes; I think it's a bit cleaner now, though I did not remove the `isOne()` check because we might as well make the IR slightly smaller so compile times are slightly faster. Very, very, VERY slightly. :-D
https://github.com/llvm/llvm-project/pull/141621
More information about the cfe-commits
mailing list