[all-commits] [llvm/llvm-project] ca5fd0: [clang] Fix crashes when passing VLA to va_arg (#1...

天音あめ via All-commits all-commits at lists.llvm.org
Tue Jan 7 04:50:05 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ca5fd06366448c94e1da085984e9e69f8d6398c3
      https://github.com/llvm/llvm-project/commit/ca5fd06366448c94e1da085984e9e69f8d6398c3
  Author: 天音あめ <i at amane-a.me>
  Date:   2025-01-07 (Tue, 07 Jan 2025)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/CodeGen/CGCall.cpp
    M clang/lib/CodeGen/CGExprScalar.cpp
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/CodeGen/xcore-abi.c
    M clang/test/Sema/varargs.c

  Log Message:
  -----------
  [clang] Fix crashes when passing VLA to va_arg (#119563)

Closes #119360.

This bug occurs when passing a VLA to `va_arg`. Since the return value
is inferred to be an array, it triggers
`ScalarExprEmitter::VisitCastExpr`, which converts it to a pointer and
subsequently calls `CodeGenFunction::EmitAggExpr`. At this point,
because the inferred type is an `AggExpr` instead of a `ScalarExpr`,
`ScalarExprEmitter::VisitVAArgExpr` is not invoked, and as a result,
`CodeGenFunction::EmitVariablyModifiedType` is also not called, leading
to the size of the VLA not being retrieved.
The solution is to move the call to
`CodeGenFunction::EmitVariablyModifiedType` into
`CodeGenFunction::EmitVAArg`, ensuring that the size of the VLA is
correctly obtained regardless of whether the expression is an `AggExpr`
or a `ScalarExpr`.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list