[all-commits] [llvm/llvm-project] 657e95: [clang] Add tests for statement expression in init...

Anders Waldenborg via All-commits all-commits at lists.llvm.org
Tue Jun 14 14:18:19 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 657e954939c8a7d33c40291ef3214333a1e2ca5b
  Author: Anders Waldenborg <anders at 0x63.nu>
  Date:   2022-06-14 (Tue, 14 Jun 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    A clang/test/CodeGen/stmtexpr-init.c
    A clang/test/Sema/stmtexpr-init.c

  Log Message:
  [clang] Add tests for statement expression in initializers

The commit 683e83c5
  [Clang][C++2b] P2242R3: Non-literal variables [...] in constexpr
fixed a code generation bug when using (C-extension) statement
expressions inside initializer expressions.

Before that commit a nested static initializer inside the statement
expression would not be emitted, causing it to be zero initialized.

It is a bit surprising (at least to me) that a commit implementing a new
C++ feature would fix this code generation bug. Zooming in it is the
change done in ExprConstant.cpp that helps. That changes so that
"ESR_Failed" is returned in more cases, causing the expression to not be
deemed constant. This fixes the code generation as instead the compiler
has to resort to generating a dynamic initializer.

That commit also meant that some statement expressions (in particular
the ones using static variables) that previously were accepted now are
errors due to not being constant (matching GCC behavior).

Given how a seemingly unrelated change caused this behavior to change,
it is probably a good thing to add at least some rudimentary tests for
these kind expressions.

Differential Revision: https://reviews.llvm.org/D127201

More information about the All-commits mailing list