[clang] [clang] assume_aligned incorrectly diagnoses a dependent return type (PR #111573)

Amr Hesham via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 8 11:14:30 PDT 2024


https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/111573

Fix `assume_aligned` incorrectly diagnoses a dependent return type

Fixes: #111563

>From fd3247ecb2fb2c83e8441d082a446c85e6268146 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
Date: Tue, 8 Oct 2024 20:12:45 +0200
Subject: [PATCH] [clang] assume_aligned incorrectly diagnoses a dependent
 return type

---
 clang/lib/Sema/SemaDeclAttr.cpp                    | 2 ++
 clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp | 3 +++
 2 files changed, 5 insertions(+)

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>();



More information about the cfe-commits mailing list