[all-commits] [llvm/llvm-project] e327b5: [C2x] reject type definitions in offsetof

Yingchi Long via All-commits all-commits at lists.llvm.org
Thu Jan 12 23:34:24 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e327b52766ed497e4779f4e652b9ad237dfda8e6
      https://github.com/llvm/llvm-project/commit/e327b52766ed497e4779f4e652b9ad237dfda8e6
  Author: Yingchi Long <i at lyc.dev>
  Date:   2023-01-13 (Fri, 13 Jan 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/include/clang/Parse/Parser.h
    M clang/include/clang/Parse/RAIIObjectsForParser.h
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Parse/ParseDecl.cpp
    M clang/lib/Parse/ParseDeclCXX.cpp
    M clang/lib/Parse/ParseExpr.cpp
    M clang/lib/Sema/SemaDecl.cpp
    M clang/lib/Sema/SemaDeclCXX.cpp
    M clang/lib/Sema/SemaTemplate.cpp
    A clang/test/C/C2x/n2350.c
    M clang/test/C/drs/dr4xx.c
    M clang/test/Parser/declarators.c
    M clang/test/SemaCXX/offsetof.cpp

  Log Message:
  -----------
  [C2x] reject type definitions in offsetof

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm made very
clear that it is an UB having type definitions with in offsetof. After
this patch clang will reject any type definitions in __builtin_offsetof.

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

```
local/offsetof.c:10:38: error: 'struct S' cannot be defined in '__builtin_offsetof'
    return __builtin_offsetof(struct S{ int a, b;}, a);
                                     ^
```

Reviewed By: aaron.ballman, #clang-language-wg

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




More information about the All-commits mailing list