[clang] 3caedfd - [clang] Fix pretty-printing assume_aligned attributes (#67331)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 26 07:55:09 PDT 2023
Author: Balazs Benics
Date: 2023-09-26T16:55:04+02:00
New Revision: 3caedfd1f2f012738fbd86008e190b95673e605c
URL: https://github.com/llvm/llvm-project/commit/3caedfd1f2f012738fbd86008e190b95673e605c
DIFF: https://github.com/llvm/llvm-project/commit/3caedfd1f2f012738fbd86008e190b95673e605c.diff
LOG: [clang] Fix pretty-printing assume_aligned attributes (#67331)
Inside `writePrettyPrintFunction()`, we check if we need to emit the
given argument:
```C++
if (!arg->isOptional() || arg->getIsOmitted() == "false") {
FoundNonOptArg = true;
continue;
}
```
For the `AssumeAligned` attribute, the second argument was optional, but
the `getIsOmitted()` returned `false`, thus we treated this argument as
**non-optional** in the end because of that disjunction.
It was because `getIsOmitted()` did not account for `Expr *` type, and
returned `false` on the fallthrough branch.
Fixes #67156
Added:
Modified:
clang/test/AST/attr-print-emit.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
Removed:
################################################################################
diff --git a/clang/test/AST/attr-print-emit.cpp b/clang/test/AST/attr-print-emit.cpp
index cc7413baf10e87a..8c48eb92daba5ee 100644
--- a/clang/test/AST/attr-print-emit.cpp
+++ b/clang/test/AST/attr-print-emit.cpp
@@ -2,6 +2,12 @@
// RUN: %clang -emit-ast -o %t.ast %s
// RUN: %clang_cc1 %t.ast -ast-print | FileCheck %s
+// CHECK: void *aa() __attribute__((assume_aligned(64)));
+void *aa() __attribute__((assume_aligned(64)));
+
+// CHECK: void *aa2() __attribute__((assume_aligned(64, 8)));
+void *aa2() __attribute__((assume_aligned(64, 8)));
+
// CHECK: void xla(int a) __attribute__((xray_log_args(1)));
void xla(int a) __attribute__((xray_log_args(1)));
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index a015ec36a30dc9e..adaee8cc92c1507 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -320,12 +320,19 @@ namespace {
}
std::string getIsOmitted() const override {
- if (type == "IdentifierInfo *")
+ auto IsOneOf = [](StringRef subject, auto... list) {
+ return ((subject == list) || ...);
+ };
+
+ if (IsOneOf(type, "IdentifierInfo *", "Expr *"))
return "!get" + getUpperName().str() + "()";
- if (type == "TypeSourceInfo *")
+ if (IsOneOf(type, "TypeSourceInfo *"))
return "!get" + getUpperName().str() + "Loc()";
- if (type == "ParamIdx")
+ if (IsOneOf(type, "ParamIdx"))
return "!get" + getUpperName().str() + "().isValid()";
+
+ assert(IsOneOf(type, "unsigned", "int", "bool", "FunctionDecl *",
+ "VarDecl *"));
return "false";
}
More information about the cfe-commits
mailing list