Skip to content

Commit b159108

Browse files
committed
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
1 parent 3723868 commit b159108

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/include/clang/Sema/DeclSpec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ class DeclSpec {
516516
SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
517517

518518
SourceLocation getTypeSpecTypeNameLoc() const {
519-
assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
519+
assert(isDeclRep((TST)TypeSpecType) || isTypeRep((TST)TypeSpecType) ||
520+
isExprRep((TST)TypeSpecType));
520521
return TSTNameLoc;
521522
}
522523

clang/test/Sema/typerep-typespec.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -std=c11 %s -fsyntax-only -verify
2+
// REQUIRES: asserts
3+
4+
struct dispatch_object_s;
5+
void _dispatch_queue_get_head(struct dispatch_object_s *volatile dq_items_head) {
6+
(_Atomic __typeof__(dq_items_head) *)0; // expected-warning{{expression result unused}}
7+
}
8+
void g(void) {
9+
(_Atomic __typeof__(struct dispatch_object_s *volatile) *)0; // expected-warning{{expression result unused}}
10+
}

0 commit comments

Comments
 (0)