Skip to content

Replace current_expr_value with expression temporaries. #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup code.
  • Loading branch information
dtarditi committed Aug 10, 2018
commit 385ebdefbf89b7f91879e92e309f062bea5ace2c
2 changes: 1 addition & 1 deletion include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
// This file defines the Expr interface and subclasses.
//
//===------------------------itional----------------------------------------------===//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_EXPR_H
#define LLVM_CLANG_AST_EXPR_H
Expand Down
2 changes: 1 addition & 1 deletion include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -9546,7 +9546,7 @@ def err_bounds_type_annotation_lost_checking : Error<
"only reference parameters from its own parameter list)">;

def err_return_value_not_in_scope : Error<
"_Return_value_ can be used only in a return bounds expression">;
"_Return_value can be used only in a return bounds expression">;

def err_expected_bounds : Error<
"expression has unknown bounds">;
Expand Down
6 changes: 3 additions & 3 deletions include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1773,9 +1773,9 @@ class Parser : public CodeCompletionHandler {
BoundsAnnotations &Result,
const Declarator &D);

// Delay parse a bounds expression in Toks. Used to parse return bounds in
// function types, after the return type is known. Stores the bounds expresion
// in Result. Returns true if there was a parsing error.
// Delay parse a return bounds expression in Toks. Used to parse return
// bounds after the return type has been constructed. Stores the bounds
// expression in Result. Returns true if there was a parsing error.
static bool ParseBoundsCallback(void *P,
std::unique_ptr<CachedTokens> Toks,
ArrayRef<ParmVarDecl *> Params,
Expand Down
21 changes: 4 additions & 17 deletions include/clang/Sema/DeclSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -1320,10 +1320,6 @@ struct DeclaratorChunk {
/// specified.
unsigned HasTrailingReturnType : 1;

/// ReturnBoundsParsefailure - if this is true, parsing of return bounds
/// failed. This information is used for error recovery.
unsigned ReturnBoundsParseFailure : 1;

/// The location of the left parenthesis in the source.
unsigned LParenLoc;

Expand Down Expand Up @@ -1382,7 +1378,9 @@ struct DeclaratorChunk {

/// The annotations for the value returned by the function. We store them
// as individual fields because the return bounds are deferred-parsed.
// Note: ReturnBounds is the only pointer to CachedTokens.
// Note: ReturnBounds is actually a unique_ptr. However unique_ptr requires
// a constructor and this struct can't have one, so so we cast it to a
// a regular pointer type.
CachedTokens *ReturnBounds;
InteropTypeExpr *ReturnInteropType;

Expand Down Expand Up @@ -1532,16 +1530,6 @@ struct DeclaratorChunk {

/// \brief Get the trailing-return-type for this function declarator.
ParsedType getTrailingReturnType() const { return TrailingReturnType; }
/*
/// \brief The bounds annotations for the return value
BoundsAnnotations getReturnAnnots() const {
return BoundsAnnotations(ReturnBounds, ReturnInteropType);
}
*/

bool getReturnBoundsParseFailure() const {
return ReturnBoundsParseFailure;
}
};

struct BlockPointerTypeInfo : TypeInfoCommon {
Expand Down Expand Up @@ -1689,7 +1677,6 @@ struct DeclaratorChunk {
SourceLocation ReturnAnnotsColonLoc,
InteropTypeExpr *ReturnInteorpTypeExpr,
std::unique_ptr<CachedTokens> ReturnBounds,
bool ReturnBoundsParseFailure,
Declarator &TheDeclarator,
TypeResult TrailingReturnType =
TypeResult());
Expand Down Expand Up @@ -1898,7 +1885,7 @@ class Declarator {
/// \brief The asm label, if specified.
Expr *AsmLabel;

/// \biref The return bounds for a function declarator.
/// \brief The return bounds for a function declarator.
BoundsExpr *ReturnBounds;
#ifndef _MSC_VER
union {
Expand Down
2 changes: 1 addition & 1 deletion include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ class Sema {
/// Push the parameters of D, which must be a function, into scope.
void ActOnReenterFunctionContext(Scope* S, Decl* D);
void ActOnExitFunctionContext();

/// Push the parameters listed in Params into scope.
void ActOnSetupParametersAgain(Scope* S, ArrayRef<ParmVarDecl *> Params);

Expand Down
2 changes: 1 addition & 1 deletion include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ namespace clang {
EXPR_INTEROPTYPE_BOUNDS_ANNOTATION,// InteropTypeBoundsAnnotation
EXPR_POSITIONAL_PARAMETER_EXPR, // PositionalParameterExpr
EXPR_BOUNDS_CAST,
EXPR_BOUNDS_VALUE_EXPR, // BoundsValueEXpr
EXPR_BOUNDS_VALUE_EXPR, // BoundsValueExpr
// OpenCL
EXPR_ASTYPE, // AsTypeExpr

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,7 @@ void ASTDumper::VisitPositionalParameterExpr(

void ASTDumper::VisitBoundsValueExpr(const BoundsValueExpr *Node) {
VisitExpr(Node);
OS << (Node->getKind() == BoundsValueExpr::Kind::Current ?
OS << (Node->getKind() == BoundsValueExpr::Kind::Current ?
"_Current_expr_value" : "_Return_value");
}

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/StmtPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ void StmtPrinter::VisitBoundsCastExpr(BoundsCastExpr *Node) {
OS << ')';
}

// is used in the representation of bounds
// PositionalParameterExpr is used in the representation of bounds
// expressions that appear in function types.
//
// - If we are dumping the AST, these may appear.
Expand Down
31 changes: 3 additions & 28 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1959,30 +1959,9 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
if (getLangOpts().CheckedC) {
// In Checked C, the return bounds expression is placed after the
// parameter list for a function and before the function body.
// Handle some possible parsing errors.

// Case 1: handle the simple case of a function declarator with a
// syntactically malformed return bounds expression that is immediately
// followed by a function body. The solution is to try to skip to
// the start of the function body.
#if 0
if (!isStartOfFunctionDefinition(D)) {
unsigned Count = D.getNumTypeObjects();
const DeclaratorChunk &lastChunk = D.getTypeObject(Count - 1);
if (lastChunk.Kind == DeclaratorChunk::Function) {
if (lastChunk.Fun.ReturnBoundsParseFailure) {
// TODO: this skips too much of there are separate
// K&R style declarations of argument types.
SkipUntil(tok::l_brace,
SkipUntilFlags::StopAtSemi |
SkipUntilFlags::StopBeforeMatch);
}
}
}
#endif

// Case 2: the return bounds expression is misplaced for a complex
// function declarator. Diagnosis this, suggest a fix, and bail out.
// It is easy to misplace it. Handle the case where the return bounds
// expression is misplaced for a complex function declarator.
// Diagnosis this, suggest a fix, and bail out.
if (Tok.is(tok::colon)) {
Token Next = NextToken();
if (StartsBoundsExpression(Next) ||
Expand Down Expand Up @@ -6258,7 +6237,6 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
StartLoc = LParenLoc;
SourceLocation BoundsColonLoc;
BoundsAnnotations ReturnAnnots;
bool ReturnBoundsParseError = false;

if (isFunctionDeclaratorIdentifierList()) {
if (RequiresArg)
Expand Down Expand Up @@ -6431,8 +6409,6 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
// body. Function declarators can also be nested within other
//declarators. We don't have special-case code for recovering
// syntactically for that case.

ReturnBoundsParseError = true;
}
}
}
Expand Down Expand Up @@ -6461,7 +6437,6 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
BoundsColonLoc,
ReturnAnnots.getInteropTypeExpr(),
std::move(DeferredBoundsToks),
ReturnBoundsParseError,
D,
TrailingReturnType),
FnAttrs, EndLoc);
Expand Down
16 changes: 8 additions & 8 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,8 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
case tok::kw__Dynamic_bounds_cast:
Res = ParseBoundsCastExpression();
break;
case tok::kw__Current_expr_value:
case tok::kw__Return_value:
Res = ParseReturnValueExpression();
break;
case tok::annot_typename:
if (isStartOfObjCClassMessageMissingOpenBracket()) {
Expand Down Expand Up @@ -3580,11 +3580,12 @@ Parser::DeferredParseBoundsExpression(std::unique_ptr<CachedTokens> Toks,
return Error;
}

// Callback for parsing the return bounds expression in Toks.
bool Parser::ParseBoundsCallback(void *P,
std::unique_ptr<CachedTokens> Toks,
ArrayRef<ParmVarDecl *> Params,
BoundsAnnotations &Result,
const Declarator &D) {
std::unique_ptr<CachedTokens> Toks,
ArrayRef<ParmVarDecl *> Params,
BoundsAnnotations &Result,
const Declarator &D) {
assert(P);
Parser *TheParser = (Parser *) P;

Expand All @@ -3609,7 +3610,7 @@ bool Parser::ParseBoundsCallback(void *P,
}

ExprResult Parser::ParseReturnValueExpression() {
assert(Tok.is(tok::kw__Return_value) &&
assert(Tok.is(tok::kw__Return_value) &&
"Not bounds value expression");
SourceLocation Loc = ConsumeToken();
return Actions.ActOnReturnValueExpr(Loc);
Expand Down Expand Up @@ -3703,8 +3704,7 @@ ExprResult Parser::ParseBlockLiteralExpression() {
CaretLoc, CaretLoc,
/*ReturnAnnotsColon=*/NoLoc,
/*ReturnInteropTypeExpr=*/nullptr,
/*ReturnBoundsAnnots=*/nullptr,
/*ReturnBoundsParseFaiilure=*/false,
/*ReturnBounds=*/nullptr,
ParamInfo),
attrs, CaretLoc);

Expand Down
6 changes: 2 additions & 4 deletions lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
LParenLoc, FunLocalRangeEnd,
/*ReturnBoundsColonLoc=*/NoLoc,
/*ReturnInteropTypeExpr=*/nullptr,
/*ReturnBoundsAnnots=*/nullptr,
/*ReturnBoundsParseFaiilure=*/false,
/*ReturnBounds=*/nullptr,
D,
TrailingReturnType),
Attr, DeclEndLoc);
Expand Down Expand Up @@ -1284,8 +1283,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
DeclLoc, DeclEndLoc,
/*ReturnBoundsColonLoc=*/NoLoc,
/*ReturnInteropTypeExpr=*/nullptr,
/*ReturnBoundsAnnots=*/nullptr,
/*ReturnBoundsParseFaiilure=*/false,
/*ReturnBounds=*/nullptr,
D,
TrailingReturnType),
Attr, DeclEndLoc);
Expand Down
2 changes: 0 additions & 2 deletions lib/Sema/DeclSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,
SourceLocation ReturnAnnotsColonLoc,
InteropTypeExpr *ReturnInteropTypeExpr,
std::unique_ptr<CachedTokens> ReturnBounds,
bool ReturnBoundsParseFailure,
Declarator &TheDeclarator,
TypeResult TrailingReturnType) {
assert(!(TypeQuals & DeclSpec::TQ_atomic) &&
Expand Down Expand Up @@ -218,7 +217,6 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,
I.Fun.TrailingReturnType = TrailingReturnType.get();
I.Fun.ReturnAnnotsColonLoc = ReturnAnnotsColonLoc.getRawEncoding();
I.Fun.ReturnBounds = ReturnBounds.release();
I.Fun.ReturnBoundsParseFailure = ReturnBoundsParseFailure;
I.Fun.ReturnInteropType = ReturnInteropTypeExpr;

assert(I.Fun.TypeQuals == TypeQuals && "bitfield overflow");
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13964,8 +13964,7 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
Loc, Loc,
/*ReturnAnnotsColonLoc=*/NoLoc,
/*ReturnInteropTypeExpr=*/nullptr,
/*ReturnBoundsAnnots=*/nullptr,
/*ReturnBoundsParseFaiilure=*/false,
/*ReturnBounds=*/nullptr,
D),
DS.getAttributes(),
SourceLocation());
Expand Down
30 changes: 14 additions & 16 deletions lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ static void maybeSynthesizeBlockSignature(TypeProcessingState &state,
/*ReturnAnnotsColon=*/NoLoc,
/*ReturnInteropTypeExpr=*/nullptr,
/*ReturnBoundsAnnots=*/nullptr,
/*ReturnBoundsParseFaiilure=*/false,
declarator));

// For consistency, make sure the state still has us as processing
Expand Down Expand Up @@ -4833,21 +4832,20 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
for (unsigned i = 0, e = FTI.NumParams; i != e; ++i) {
ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[i].Param);
ParamVars.push_back(Param);
}
Sema::CheckedCReturnValueRAII ReturnValueRAII(S, T);
std::unique_ptr<CachedTokens> ReturnBoundsTokens(FTI.ReturnBounds);
assert(S.DeferredBoundsParser);
if (S.DeferredBoundsParser(S.DeferredBoundsParserData,
std::move(ReturnBoundsTokens),
ParamVars,
ReturnAnnots,
D))
D.setInvalidType();
else
D.setReturnBounds(ReturnAnnots.getBoundsExpr());


assert(!ReturnAnnots.getInteropTypeExpr() &&
}
Sema::CheckedCReturnValueRAII ReturnValueRAII(S, T);
std::unique_ptr<CachedTokens> ReturnBoundsTokens(FTI.ReturnBounds);
assert(S.DeferredBoundsParser);
if (S.DeferredBoundsParser(S.DeferredBoundsParserData,
std::move(ReturnBoundsTokens),
ParamVars,
ReturnAnnots,
D))
D.setInvalidType();
else
D.setReturnBounds(ReturnAnnots.getBoundsExpr());

assert(!ReturnAnnots.getInteropTypeExpr() &&
"should only have parsed bounds expression");
}

Expand Down
1 change: 0 additions & 1 deletion lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,6 @@ class TreeTransform {
ExprResult RebuildBoundsValueExpr(SourceLocation Loc, QualType Ty, BoundsValueExpr::Kind K) {
return new (getSema().Context) BoundsValueExpr(Loc, Ty, K);
}


/// \brief Build a new overloaded operator call expression.
///
Expand Down