[PATCH] D105287: Fix an accepts-invalid issue with [[]] attributes in the type position in C

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 1 07:54:42 PDT 2021


aaron.ballman created this revision.
aaron.ballman added reviewers: erichkeane, rsmith.
aaron.ballman requested review of this revision.
Herald added a project: clang.

A user reported an issue to me via email that Clang was accepting some code that GCC was rejecting. After investigation, it turned out to be a general problem of us failing to properly reject attributes written in the type position in C when they don't apply to types. The root cause was a terminology issue -- we sometimes use "CXX11Attr" to mean [[]] in C++11 mode and sometimes [[]] in general -- and this came back to bite us because in this particular case, it really meant [[]] in C++ mode.

I fixed the issue by introducing a new function `AttributeCommonInfo::isStandardAttributeSyntax()` to represent [[]] in either C or C++ mode. I toyed with `isDoubleSquareBracketAttributeSyntax()` instead, but because of attributes like `alignas`, it didn't feel like a particularly good match.

This fix pointed out that we've had the issue in some of our existing tests, which have all been corrected. This resolves https://bugs.llvm.org/show_bug.cgi?id=50954.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105287

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-c-attr.c
  clang/test/Sema/attr-availability-square-brackets.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-deprecated-c2x.c
  clang/test/Sema/attr-external-source-symbol.c
  clang/test/Sema/c2x-maybe_unused-errors.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105287.355880.patch
Type: text/x-patch
Size: 12836 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210701/38924636/attachment.bin>


More information about the cfe-commits mailing list