[all-commits] [llvm/llvm-project] 610ec9: [clang] allow const structs/unions/arrays to be co...

Nick Desaulniers via All-commits all-commits at lists.llvm.org
Wed Aug 2 15:33:06 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 610ec954e1f81c0e8fcadedcd25afe643f5a094e
      https://github.com/llvm/llvm-project/commit/610ec954e1f81c0e8fcadedcd25afe643f5a094e
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-08-02 (Wed, 02 Aug 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/AST/ExprConstant.cpp
    M clang/test/CodeGen/builtin-constant-p.c
    M clang/test/CodeGen/const-init.c
    M clang/test/Sema/builtins.c
    M clang/test/Sema/init.c

  Log Message:
  -----------
  [clang] allow const structs/unions/arrays to be constant expressions for C

For code like:
struct foo { ... };
struct bar { struct foo foo; };
const struct foo my_foo = { ... };
struct bar my_bar = { .foo = my_foo };

Eli Friedman points out the relevant part of the C standard seems to
have some flexibility in what is considered a constant expression:

6.6 paragraph 10:
An implementation may accept other forms of constant expressions.

GCC 8 added support for these, so clang not supporting them has been a
constant thorn in the side of source code portability within the Linux
kernel.

Fixes: https://github.com/llvm/llvm-project/issues/44502

Reviewed By: efriedma

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




More information about the All-commits mailing list