[clang] [clang] Fix pretty-printing assume_aligned attributes (PR #67331)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 25 06:44:56 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
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.
The fix is easy and generic: just check if the type is a pointer.
Fixes #<!-- -->67156
---
Full diff: https://github.com/llvm/llvm-project/pull/67331.diff
2 Files Affected:
- (modified) clang/test/AST/attr-print-emit.cpp (+6)
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+4-3)
``````````diff
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 7ea09058c3d39f2..56e87e5d05948a3 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -320,10 +320,11 @@ namespace {
}
std::string getIsOmitted() const override {
- if (type == "IdentifierInfo *")
- return "!get" + getUpperName().str() + "()";
- if (type == "TypeSourceInfo *")
+ StringRef T = type;
+ if (T == "TypeSourceInfo *")
return "!get" + getUpperName().str() + "Loc()";
+ if (T.ends_with(" *"))
+ return "!get" + getUpperName().str() + "()";
if (type == "ParamIdx")
return "!get" + getUpperName().str() + "().isValid()";
return "false";
``````````
</details>
https://github.com/llvm/llvm-project/pull/67331
More information about the cfe-commits
mailing list