[clang] b159108 - Sema: adjust assertion to account for deduced types

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 10:50:08 PDT 2022


Author: Saleem Abdulrasool
Date: 2022-05-24T17:49:44Z
New Revision: b159108bc5ebd7f37373896ece1da8f49612f7a6

URL: https://github.com/llvm/llvm-project/commit/b159108bc5ebd7f37373896ece1da8f49612f7a6
DIFF: https://github.com/llvm/llvm-project/commit/b159108bc5ebd7f37373896ece1da8f49612f7a6.diff

LOG: Sema: adjust assertion to account for deduced types

Previous changes for the BTF attributes introduced a new sub-tree
visitation.  That uncovered that when accessing the typespec location we
would assert that the type specification is either a type declaration or
`typename`.  However, `typename` was explicitly permitted.  This change
predates the introduction of newer deduced type representations such as
`__underlying_type` from C++ and the addition of the GNU `__typeof__`
expression.

Thanks to aaron.ballman for the valuable discussion and pointer to
`isTypeRep`.

Differential Revision: https://reviews.llvm.org/D126093
Reviewed By: aaron.ballman, yonghong-song

Added: 
    clang/test/Sema/typerep-typespec.c

Modified: 
    clang/include/clang/Sema/DeclSpec.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index 6a7fbe8282d85..c03ead9c79b34 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -516,7 +516,8 @@ class DeclSpec {
   SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
 
   SourceLocation getTypeSpecTypeNameLoc() const {
-    assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
+    assert(isDeclRep((TST)TypeSpecType) || isTypeRep((TST)TypeSpecType) ||
+           isExprRep((TST)TypeSpecType));
     return TSTNameLoc;
   }
 

diff  --git a/clang/test/Sema/typerep-typespec.c b/clang/test/Sema/typerep-typespec.c
new file mode 100644
index 0000000000000..001131306a4a9
--- /dev/null
+++ b/clang/test/Sema/typerep-typespec.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c11 %s -fsyntax-only -verify
+// REQUIRES: asserts
+
+struct dispatch_object_s;
+void _dispatch_queue_get_head(struct dispatch_object_s *volatile dq_items_head) {
+  (_Atomic __typeof__(dq_items_head) *)0; // expected-warning{{expression result unused}}
+}
+void g(void) {
+  (_Atomic __typeof__(struct dispatch_object_s *volatile) *)0; // expected-warning{{expression result unused}}
+}


        


More information about the cfe-commits mailing list