-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang] assume_aligned incorrectly diagnoses a dependent return type #111573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] assume_aligned incorrectly diagnoses a dependent return type #111573
Conversation
|
@llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) ChangesFix Fixes: #111563 Full diff: https://github.com/llvm/llvm-project/pull/111573.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index af983349a89b58..c1d1ef31db6e92 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1217,6 +1217,8 @@ static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
bool Sema::isValidPointerAttrType(QualType T, bool RefOkay) {
if (RefOkay) {
+ if (T->isDependentType())
+ return true;
if (T->isReferenceType())
return true;
} else {
diff --git a/clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp b/clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp
index 61b85557d6b294..4459580cdccc5d 100644
--- a/clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp
+++ b/clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp
@@ -52,6 +52,9 @@ T *atest3() __attribute__((assume_aligned(31, o))); // expected-error {{requeste
template <typename T, int o>
T *atest4() __attribute__((assume_aligned(32, o)));
+template<typename T>
+T atest5(int) __attribute__((assume_aligned(2)));
+
void test22() {
atest3<int, 5>();
atest4<int, 5>();
|
| T *atest4() __attribute__((assume_aligned(32, o))); | ||
|
|
||
| template<typename T> | ||
| T atest5(int) __attribute__((assume_aligned(2))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change causes a number of attributes to change their behavior (see all uses of isValidPointerAttrType), so we should test each of those.
Additionally, we should separately check (via a different declaration) that the diagnostic fires when instantiated.
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
|
|
||
| bool Sema::isValidPointerAttrType(QualType T, bool RefOkay) { | ||
| if (RefOkay) { | ||
| if (T->isDependentType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem like the right place for this, we should be skipping ANY time the type is dependent, not only when a ref argument is acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think you, updated
fd3247e to
076c867
Compare
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably valuable to audit the other uses of this function well, and remove checks for dependence there as redundant. And probably ensure the documentation of this function mentions that it skips on dependence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please check the updated documentation of the function
076c867 to
4202153
Compare
clang/include/clang/Sema/Sema.h
Outdated
| /// attributes. By default, we look through references (the behavior used by | ||
| /// nonnull), but if the second parameter is true, then we treat a reference | ||
| /// type as valid. | ||
| /// attributes. By default, we skip dependence and look through references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by default implies that the dependence check can bie disabled, but it very much cannot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, all comments addressed
dea97ae to
036f765
Compare
|
This part in ObjectiveC tests conflict with the current solution, any suggestion how we can go around it right now until to be handled later llvm-project/clang/test/SemaObjCXX/noescape.mm Lines 202 to 205 in 18952bd
|
clang/include/clang/Sema/Sema.h
Outdated
| /// attributes. By default, we look through references (the behavior used by | ||
| /// nonnull), but if the second parameter is true, then we treat a reference | ||
| /// type as valid. | ||
| /// attributes. We skip dependence By default, we look through references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, we're not skipping dependence by default, we're ALWAYS skipping dependence. We skip references (presumably by default). I think the dependence behavior just needs its own sentence here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i think i was planning to make it like We skip dependence and By default ..., or We skip dependence then By default ...
Doesn't the fixme above that say it was diagnosing unintentionally? If so, that fixme likely needs to be removed, and this is 'correct' now. |
Yes but still got |
3e83fd9 to
d3f8538
Compare
I handled it, i didn't know that Thank you |
clang/include/clang/Sema/Sema.h
Outdated
| /// attributes. By default, we look through references (the behavior used by | ||
| /// nonnull), but if the second parameter is true, then we treat a reference | ||
| /// type as valid. | ||
| /// attributes. We skip dependence then By default, we look through references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// attributes. We skip dependence then By default, we look through references | |
| /// attributes. Dependent types are considered valid, so they can be checked during instantiation time. By default, we look through references |
^^ make sure to clang-format.
d3f8538 to
a0066f7
Compare
clang/include/clang/Sema/Sema.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// treat a reference type as valid.. | |
| /// treat a reference type as valid. |
Missed this!
clang/include/clang/Sema/Sema.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// attributes. Dependent types are considered valid, so they can be checked | |
| /// attributes. Dependent types are considered valid so they can be checked |
a0066f7 to
0f1405e
Compare
…lvm#111573) Fix `assume_aligned` incorrectly diagnoses a dependent return type Fixes: llvm#111563
Fix
assume_alignedincorrectly diagnoses a dependent return typeFixes: #111563