[all-commits] [llvm/llvm-project] 79f87b: [clang] Fix several issues in the generated AttrHa...

Sergei Barannikov via All-commits all-commits at lists.llvm.org
Mon Oct 9 23:04:19 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 79f87be6888d13a94661be9d8908c83dd2229c9b
      https://github.com/llvm/llvm-project/commit/79f87be6888d13a94661be9d8908c83dd2229c9b
  Author: Sergei Barannikov <barannikov88 at gmail.com>
  Date:   2023-10-10 (Tue, 10 Oct 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/test/Preprocessor/has_attribute.c
    M clang/test/Preprocessor/has_attribute.cpp
    M clang/test/Preprocessor/has_c_attribute.c
    M clang/utils/TableGen/ClangAttrEmitter.cpp

  Log Message:
  -----------
  [clang] Fix several issues in the generated AttrHasAttributeImpl.inc

1. The generated file contained a lot of duplicate switch cases, e.g.:
```
switch (Syntax) {
case AttributeCommonInfo::Syntax::AS_GNU:
  return llvm::StringSwitch<int>(Name)
...
    .Case("error", 1)
    .Case("warning", 1)
    .Case("error", 1)
    .Case("warning", 1)
```

2. Some attributes were listed in wrong places, e.g.:
```
case AttributeCommonInfo::Syntax::AS_CXX11: {
if (ScopeName == "") {
  return llvm::StringSwitch<int>(Name)
...
    .Case("warn_unused_result", LangOpts.CPlusPlus11 ? 201907 : 0)
```

`warn_unused_result` is a non-standard attribute and should not be
available as [[warn_unused_result]].

3. Some attributes had the wrong version, e.g.:
```
case AttributeCommonInfo::Syntax::AS_CXX11: {
} else if (ScopeName == "gnu") {
  return llvm::StringSwitch<int>(Name)
...
    .Case("fallthrough", LangOpts.CPlusPlus11 ? 201603 : 0)
```

[[gnu::fallthrough]] is a non-standard spelling and should not have the
standard version. Instead, __has_cpp_attribute should return 1 for it.

There is another issue with attributes that share spellings, e.g.:
```
    .Case("interrupt", true && (T.getArch() == llvm::Triple::arm || ...) ? 1 : 0)
    .Case("interrupt", true && (T.getArch() == llvm::Triple::avr) ? 1 : 0)
...
    .Case("interrupt", true && (T.getArch() == llvm::Triple::riscv32 || ...) ? 1 : 0)
```
As can be seen, __has_attribute(interrupt) would only return true for
ARM targets. This patch does not address this issue.

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




More information about the All-commits mailing list