Skip to content

Commit

Permalink
[AST] Handle AtomicType in ASTContext::getNonProvenanceCarryingType
Browse files Browse the repository at this point in the history
Fixes #656
  • Loading branch information
jrtc27 committed Aug 18, 2023
1 parent 2f2dd31 commit 0487abc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10900,7 +10900,10 @@ QualType ASTContext::getNonProvenanceCarryingType(QualType T) const {
// if (!Target->SupportsCapabilities())
// return T; // XXX: should probably assert instead?
assert(Target->SupportsCapabilities());
// Must be called with either intcap_t or uintcap_t
// Must be called with either intcap_t or uintcap_t (or atomic variants
// thereof)
if (const AtomicType *AT = dyn_cast<AtomicType>(T.getCanonicalType()))
return getAtomicType(getNonProvenanceCarryingType(AT->getValueType()));
if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getCanonicalType())) {
if (BT->getKind() == BuiltinType::IntCap)
return NoProvenanceIntCapTy;
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Sema/cheri/atomic-init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %cheri_cc1 %s -ast-dump | FileCheck %s
// RUN: %cheri_purecap_cc1 %s -ast-dump | FileCheck %s

/// Crashed with "Invalid type passed to getNonProvenanceCarryingType" due to
/// not handling AtomicType
// CHECK: VarDecl {{.*}} <{{.*}}:[[@LINE+4]]:1, col:22> col:18 x '_Atomic(__intcap)' cinit
// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:22> '_Atomic(__intcap __attribute__((cheri_no_provenance)))' <NonAtomicToAtomic>
// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:22> '__intcap __attribute__((cheri_no_provenance))':'__intcap' <IntegralCast>
// CHECK-NEXT: IntegerLiteral {{.*}} <col:22> 'int' 0
_Atomic __intcap x = 0;

0 comments on commit 0487abc

Please sign in to comment.