Skip to content

Commit

Permalink
Rename BOUNDS_CHECKED pragma to CHECKED_SCOPE. (#485)
Browse files Browse the repository at this point in the history
- Rename pragma and associated methods within the compiler.
- Update tests
- There are corresponding commits to the Checked C and the Checked C LNT also.

Testing:
- Passed local testing on Windows and automated testing on Linux.
  • Loading branch information
dtarditi authored Apr 26, 2018
1 parent 9f9ccfc commit b88a40f
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,10 @@ ANNOTATION(pragma_fp)
// Annotation for the attribute pragma directives - #pragma clang attribute ...
ANNOTATION(pragma_attribute)

// Annotations for BOUNDS_CHECKED pragma directives for checkedc
// Annotations for CHECKED_SCOPE pragma directives for checkedc
// The lexer produces these so that they only take effect when the parser
// handles #pragma BOUNDS_CHECKED ... directives.
ANNOTATION(pragma_bounds_checked)
// handles #pragma CHECKED_SCOPE ... directives.
ANNOTATION(pragma_checked_scope)

// Annotations for module import translated from #include etc.
ANNOTATION(module_include)
Expand Down
4 changes: 2 additions & 2 deletions include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ class Parser : public CodeCompletionHandler {
void HandlePragmaAttribute();

/// \brief Handle the annotation token produced for
/// #pragma BOUNDS_CHECKED [on-off-switch]
void HandlePragmaBoundsChecked();
/// #pragma CHECKED_SCOPE [on-off-switch]
void HandlePragmaCheckedScope();

/// GetLookAheadToken - This peeks ahead N tokens and returns that token
/// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1)
Expand Down
4 changes: 2 additions & 2 deletions include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -4657,8 +4657,8 @@ class Sema {
/// \brief Add default bounds/interop type expressions to Annots, if appropriate.
void InferBoundsAnnots(QualType Ty, BoundsAnnotations &Annots, bool IsParam);

// \#pragma BOUNDS_CHECKED.
void ActOnPragmaBoundsChecked(Scope *S, tok::OnOffSwitch OOS);
// \#pragma CHECKED_SCOPE.
void ActOnPragmaCheckedScope(Scope *S, tok::OnOffSwitch OOS);

// Represents the context where an expression must be non-modifying.
enum NonModifyingContext {
Expand Down
4 changes: 2 additions & 2 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4100,8 +4100,8 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, unsigned TagType,
continue;
}

if (Tok.is(tok::annot_pragma_bounds_checked)) {
HandlePragmaBoundsChecked();
if (Tok.is(tok::annot_pragma_checked_scope)) {
HandlePragmaCheckedScope();
continue;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Parse/ParsePragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ struct PragmaForceCUDAHostDeviceHandler : public PragmaHandler {
};

struct PragmaCheckedScopeHandler : public PragmaHandler {
PragmaCheckedScopeHandler() : PragmaHandler("BOUNDS_CHECKED") {}
PragmaCheckedScopeHandler() : PragmaHandler("CHECKED_SCOPE") {}
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
Token &FirstToken) override;
};
Expand Down Expand Up @@ -1431,13 +1431,13 @@ void Parser::HandlePragmaAttribute() {
std::move(SubjectMatchRules));
}

// #pragma BOUNDS_CHECKED [on-off-switch]
void Parser::HandlePragmaBoundsChecked() {
assert(Tok.is(tok::annot_pragma_bounds_checked));
// #pragma CHECKED_SCOPE [on-off-switch]
void Parser::HandlePragmaCheckedScope() {
assert(Tok.is(tok::annot_pragma_checked_scope));
tok::OnOffSwitch OOS =
static_cast<tok::OnOffSwitch>(
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
Actions.ActOnPragmaBoundsChecked(Actions.getCurScope(), OOS);
Actions.ActOnPragmaCheckedScope(Actions.getCurScope(), OOS);
ConsumeAnnotationToken(); // The annotation token.
}

Expand Down Expand Up @@ -3019,7 +3019,7 @@ void PragmaAttributeHandler::HandlePragma(Preprocessor &PP,
}

// Handle the checked-c top level scope checked property.
// #pragma BOUNDS_CHECKED [on-off-switch]
// #pragma CHECKED_SCOPE [on-off-switch]
// To handle precise scope property, annotation token is better
void PragmaCheckedScopeHandler::HandlePragma(Preprocessor &PP,
PragmaIntroducerKind Introducer,
Expand All @@ -3031,7 +3031,7 @@ void PragmaCheckedScopeHandler::HandlePragma(Preprocessor &PP,
MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>(1),
1);
Toks[0].startToken();
Toks[0].setKind(tok::annot_pragma_bounds_checked);
Toks[0].setKind(tok::annot_pragma_checked_scope);
Toks[0].setLocation(Tok.getLocation());
Toks[0].setAnnotationEndLoc(Tok.getLocation());
Toks[0].setAnnotationValue(
Expand Down
8 changes: 4 additions & 4 deletions lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ Parser::ParseStatementOrDeclarationAfterAttributes(StmtVector &Stmts,
HandlePragmaAttribute();
return StmtEmpty();

case tok::annot_pragma_bounds_checked:
HandlePragmaBoundsChecked();
case tok::annot_pragma_checked_scope:
HandlePragmaCheckedScope();
return StmtEmpty();
}

Expand Down Expand Up @@ -966,8 +966,8 @@ void Parser::ParseCompoundStatementLeadingPragmas() {
case tok::annot_pragma_dump:
HandlePragmaDump();
break;
case tok::annot_pragma_bounds_checked:
HandlePragmaBoundsChecked();
case tok::annot_pragma_checked_scope:
HandlePragmaCheckedScope();
break;
default:
checkForPragmas = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) {
HandlePragmaUnused();
return false;

case tok::annot_pragma_bounds_checked:
HandlePragmaBoundsChecked();
case tok::annot_pragma_checked_scope:
HandlePragmaCheckedScope();
return false;

case tok::kw_import:
Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/SemaAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@ void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
OptimizeOffPragmaLocation = PragmaLoc;
}

// Checked C - #pragma BOUNDS_CHECKED action, adjust top level scope flags.
// Adjust checked property of scope where '#pragma BOUNDS_CHECKED' is set.
void Sema::ActOnPragmaBoundsChecked(Scope *S, tok::OnOffSwitch OOS) {
// Checked C - #pragma CHECKED_SCOPE action, adjust top level scope flags.
// Adjust checked property of scope where '#pragma CHECKED_SCOPE' is set.
void Sema::ActOnPragmaCheckedScope(Scope *S, tok::OnOffSwitch OOS) {
unsigned ScopeFlags = S->getFlags();
switch (OOS) {
case tok::OOS_ON:
Expand Down
8 changes: 4 additions & 4 deletions test/CheckedC/checked-scope/error-messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ extern void f4(void) _Checked {
int *p = 0; // expected-error {{local variable in a checked scope must have a checked type}}
}

#pragma BOUNDS_CHECKED ON
#pragma CHECKED_SCOPE ON
extern int *gp1; // expected-error {{global variable in a checked scope must have a checked type or a bounds-safe interface}}

struct S1 {
int *f; // expected-error {{member in a checked scope must have a checked type or a bounds-safe interface}}
};
#pragma BOUNDS_CHECKED OFF
#pragma CHECKED_SCOPE OFF

//=========================================================================================
// Error messages for uses of variables and members with unchecked types in checked scopes.
Expand Down Expand Up @@ -106,10 +106,10 @@ extern void f25(void) {
}
}

#pragma BOUNDS_CHECKED ON
#pragma CHECKED_SCOPE ON
extern ty gp3; // expected-error {{global variable in a checked scope must have a checked type or a bounds-safe interface}} \
// expected-note {{'ty' (aka 'int *') is not allowed in a checked scope}}
#pragma BOUNDS_CHECKED OFF
#pragma CHECKED_SCOPE OFF

struct S3 {
ty f; // expected-note {{member declared here}}
Expand Down
2 changes: 1 addition & 1 deletion test/CheckedC/static-checking/bounds-decl-checking-bsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int f2(_Ptr<void> p) {
return 0;
}

#pragma BOUNDS_CHECKED ON
#pragma CHECKED_SCOPE ON

extern void test_f3(const void* p_ptr : byte_count(1));

Expand Down
2 changes: 1 addition & 1 deletion test/CheckedC/static-checking/bounds-decl-checking-cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// RUN: %clang -cc1 -fcheckedc-extension -verify %s

#pragma BOUNDS_CHECKED ON
#pragma CHECKED_SCOPE ON

#include "bounds-decl-checking.c"

0 comments on commit b88a40f

Please sign in to comment.