https://github.com/steakhal created
https://github.com/llvm/llvm-project/pull/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.
The fix is easy and generic: just check if the type is a pointer.
Fixes #67156
>From b106eda609baf83c200cb1ac6a96e3b40ab0bfbe Mon Sep 17 00:00:00 2001
From: Balazs Benics <[email protected]>
Date: Mon, 25 Sep 2023 15:37:34 +0200
Subject: [PATCH] [clang] Fix pretty-printing assume_aligned attributes
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
---
clang/test/AST/attr-print-emit.cpp | 6 ++++++
clang/utils/TableGen/ClangAttrEmitter.cpp | 7 ++++---
2 files changed, 10 insertions(+), 3 deletions(-)
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";
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits