[clang] [clang] Fix crashes when passing VLA to va_arg (PR #119563)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 11 13:03:11 PST 2024


efriedma-quic wrote:

Please add a testcase to clang/test/CodeGen/ .  Put it in an existing file if there's already some related test.  (See also https://llvm.org/docs/Contributing.html#how-to-submit-a-patch )

I don't think EmitAggregateCopy is the right place to call EmitVariablyModifiedType: we want to call EmitVariablyModifiedType exactly once for every VLA written in the source code.  So the call should be located somewhere that's tightly related to the expression itself: CodeGenFunction::EmitVAArg, or something like that.

While you're here, maybe look at emitting an undefined-behavior warning for this construct?  A VLA is never compatible with a function argument: if you try to write an array in an function type, it gets promoted to a pointer.  So this construct is guaranteed to produce broken results (which is why nobody has tripped over this before).

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


More information about the cfe-commits mailing list