Skip to content

Commit 4202153

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

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
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. By default, we skip dependence and 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ 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+
5558
void test22() {
5659
atest3<int, 5>();
5760
atest4<int, 5>();

0 commit comments

Comments
 (0)