Skip to content

Commit dea97ae

Browse files
committed
[clang] assume_aligned incorrectly diagnoses a dependent return type
1 parent 7e31eaa commit dea97ae

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,9 +4453,9 @@ class Sema final : public SemaBase {
44534453
SourceLocation *ArgLocation = nullptr);
44544454

44554455
/// Determine if type T is a valid subject for a nonnull and similar
4456-
/// attributes. By default, we look through references (the behavior used by
4457-
/// nonnull), but if the second parameter is true, then we treat a reference
4458-
/// type as valid.
4456+
/// attributes. We skip dependence By default, we look through references
4457+
/// (the behavior used by nonnull), but if the second parameter is true, then
4458+
/// we treat a reference type as valid..
44594459
bool isValidPointerAttrType(QualType T, bool RefOkay = false);
44604460

44614461
/// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,8 @@ static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
12161216
}
12171217

12181218
bool Sema::isValidPointerAttrType(QualType T, bool RefOkay) {
1219+
if (T->isDependentType())
1220+
return true;
12191221
if (RefOkay) {
12201222
if (T->isReferenceType())
12211223
return true;
@@ -1284,7 +1286,7 @@ static void handleNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
12841286
for (unsigned I = 0, E = getFunctionOrMethodNumParams(D);
12851287
I != E && !AnyPointers; ++I) {
12861288
QualType T = getFunctionOrMethodParamType(D, I);
1287-
if (T->isDependentType() || S.isValidPointerAttrType(T))
1289+
if (S.isValidPointerAttrType(T))
12881290
AnyPointers = true;
12891291
}
12901292

@@ -1409,8 +1411,7 @@ void Sema::AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI,
14091411
AllocAlignAttr TmpAttr(Context, CI, ParamIdx());
14101412
SourceLocation AttrLoc = CI.getLoc();
14111413

1412-
if (!ResultType->isDependentType() &&
1413-
!isValidPointerAttrType(ResultType, /* RefOkay */ true)) {
1414+
if (!isValidPointerAttrType(ResultType, /* RefOkay */ true)) {
14141415
Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
14151416
<< &TmpAttr << CI.getRange() << getFunctionOrMethodResultSourceRange(D);
14161417
return;

clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ T *atest3() __attribute__((assume_aligned(31, o))); // expected-error {{requeste
5252
template <typename T, int o>
5353
T *atest4() __attribute__((assume_aligned(32, o)));
5454

55+
template<typename T>
56+
T atest5(int) __attribute__((assume_aligned(2)));
57+
58+
// expected-warning@+1 {{'assume_aligned' attribute only applies to return values that are pointers or references}}
59+
int atest6(int) __attribute__((assume_aligned(2)));
60+
5561
void test22() {
5662
atest3<int, 5>();
5763
atest4<int, 5>();

clang/test/SemaObjCXX/noescape.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
void noescapeFunc2(int *); // expected-error {{conflicting types for 'noescapeFunc2'}}
1818

1919
template <class T>
20-
void noescapeFunc5(__attribute__((noescape)) T); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
20+
void noescapeFunc5(__attribute__((noescape)) T);
2121
template <class T>
2222
void noescapeFunc6(__attribute__((noescape)) const T &);
2323
template <class T>

0 commit comments

Comments
 (0)