Skip to content

Commit

Permalink
Sema: adjust assertion to account for deduced types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
compnerd committed May 24, 2022
1 parent 3723868 commit b159108
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/include/clang/Sema/DeclSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions clang/test/Sema/typerep-typespec.c
Original file line number Diff line number Diff line change
@@ -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}}
}

0 comments on commit b159108

Please sign in to comment.