Skip to content

Commit

Permalink
Consistently use qualifier to refer to __capability. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
arichardson committed Jul 6, 2023
1 parent e2fae40 commit 1f044f6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def err_expected_selector_for_method : Error<
"expected selector for Objective-C method">;
def err_expected_property_name : Error<"expected property name">;

def warn_cheri_capability_attribute_location : Warning<
def warn_cheri_capability_qualifier_location : Warning<
"use of __capability before the pointer type is deprecated">,
InGroup<DeprecatedDeclarations>;

Expand Down
7 changes: 5 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,12 @@ def note_cheri_func_noproto_explanation : Note<
"values from the argument registers.">;
def note_cheri_func_decl_add_types : Note<
"candidate function declaration needs parameter types">;
def err_cheri_capability_attribute_ambiguous : Error<
def err_cheri_capability_qualifier_not_supported : Error<
"use of __capability is not supported without CHERI; "
"specify an appropriate -march= or -mcpu=">;
def err_cheri_capability_qualifier_ambiguous : Error<
"use of __capability is ambiguous">;
def err_cheri_capability_attribute_pointers_only : Error<
def err_cheri_capability_qualifier_pointers_only : Error<
"__capability only applies to pointers; type here is %0">;

def err_objc_var_decl_inclass :
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ void Parser::ParseCapabilityQualifier(ParsedAttributes &Attrs) {
// TODO: we should not treat __capability as a keyword for non-CHERI.
// See https://github.com/CTSRD-CHERI/llvm-project/issues/706.
if (!getTargetInfo().SupportsCapabilities())
Diag(AttrNameLoc, diag::err_attribute_unsupported) << AttrName << "CHERI";
Diag(AttrNameLoc, diag::err_cheri_capability_qualifier_not_supported);
else
Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
ParsedAttr::AS_Keyword);
Expand Down
21 changes: 11 additions & 10 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6372,8 +6372,7 @@ fillDependentPointerTypeLoc(DependentPointerTypeLoc DPTL,
}
}

llvm_unreachable(
"no cheri_capability attribute found at the expected location!");
llvm_unreachable("no __capability qualifier found at the expected location!");
}

static void fillMatrixTypeLoc(MatrixTypeLoc MTL,
Expand Down Expand Up @@ -8213,18 +8212,19 @@ QualType Sema::BuildPointerInterpretationAttr(QualType T,
} else if (T->isDependentType()) {
T = Context.getDependentPointerType(T, PIK, QualifierLoc);
} else {
Diag(QualifierLoc, diag::err_cheri_capability_attribute_pointers_only)
<< T;
Diag(QualifierLoc, diag::err_cheri_capability_qualifier_pointers_only) << T;
}

return T;
}

/// HandleCHERICapabilityAttr - Process the cheri_capability attribute. It is
/// HandleCHERICapabilityQualifier - Process the __capability qualifier. It is
/// only applicable to pointer and reference types and specifies that this
/// pointer/reference should be treated as a capability.
static void HandleCHERICapabilityAttr(QualType &CurType, TypeProcessingState &state,
TypeAttrLocation TAL, ParsedAttr& attr) {
static void HandleCHERICapabilityQualifier(QualType &CurType,
TypeProcessingState &state,
TypeAttrLocation TAL,
ParsedAttr &attr) {
Declarator &declarator = state.getDeclarator();
Sema& S = state.getSema();
std::string Name = attr.getAttrName()->getName().str();
Expand Down Expand Up @@ -8256,14 +8256,15 @@ static void HandleCHERICapabilityAttr(QualType &CurType, TypeProcessingState &st
if (nextChunk.Kind == DeclaratorChunk::Pointer) {
auto Attr = nextChunk.getAttrs();
if (!Attr.hasAttribute(ParsedAttr::AT_CHERICapability)) {
S.Diag(nextChunk.Loc, diag::err_cheri_capability_attribute_ambiguous);
S.Diag(nextChunk.Loc,
diag::err_cheri_capability_qualifier_ambiguous);
return;
}
}
}

// Output a deprecated usage warning with a FixItHint
S.Diag(chunk.Loc, diag::warn_cheri_capability_attribute_location)
S.Diag(chunk.Loc, diag::warn_cheri_capability_qualifier_location)
<< FixItHint::CreateRemoval(attr.getRange())
<< FixItHint::CreateInsertion(chunk.Loc.getLocWithOffset(1),
" " + Name + " ");
Expand Down Expand Up @@ -8646,7 +8647,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,

case ParsedAttr::AT_CHERICapability:
attr.setUsedAsTypeAttr();
HandleCHERICapabilityAttr(type, state, TAL, attr);
HandleCHERICapabilityQualifier(type, state, TAL, attr);
break;
case ParsedAttr::AT_CHERINoSubobjectBounds:
attr.setUsedAsTypeAttr();
Expand Down
3 changes: 1 addition & 2 deletions clang/test/Parser/capability-qualifier-non-cheri.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
// RUN: %clang_cc1 -triple riscv64 -target-feature +xcheri -fsyntax-only %s -verify=cheri
// cheri-no-diagnostics

// TODO: The message is not quite right (should use qualifier instead of attribute).
void *__capability foo; // no-cheri-error{{'__capability' attribute is not supported on targets missing CHERI; specify an appropriate -march= or -mcpu=}}
void *__capability foo; // no-cheri-error{{use of __capability is not supported without CHERI; specify an appropriate -march= or -mcpu=}}

0 comments on commit 1f044f6

Please sign in to comment.