Conversation
Prabhuk
approved these changes
Aug 16, 2018
Collaborator
Prabhuk
left a comment
There was a problem hiding this comment.
Looks good! Just a couple of alignment and comment related fixes.
lib/Parse/ParseExpr.cpp
Outdated
|
|
||
| ExprResult Parser::ParseReturnValueExpression() { | ||
| assert(Tok.is(tok::kw__Return_value) && | ||
| "Not bounds value expression"); |
Collaborator
There was a problem hiding this comment.
Double space between bounds and value in the message "Not bounds value expression"
lib/Sema/DeclSpec.cpp
Outdated
| I.Fun.ReturnAnnotsColonLoc = ReturnAnnotsColonLoc.getRawEncoding(); | ||
| I.Fun.ReturnBounds = ReturnAnnotsExpr.getBoundsExpr(); | ||
| I.Fun.ReturnInteropType = ReturnAnnotsExpr.getInteropTypeExpr(); | ||
| I.Fun.ReturnBounds = ReturnBounds.release(); |
Collaborator
There was a problem hiding this comment.
Remove space before "ReturnBounds.release()"
include/clang/Sema/DeclSpec.h
Outdated
| BoundsExpr *ReturnBounds; | ||
| // as individual fields because the return bounds are deferred-parsed. | ||
| // 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 |
Collaborator
There was a problem hiding this comment.
Double space before "However" and duplicate "so".
lib/Parse/ParseDecl.cpp
Outdated
| // 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. |
dtarditi
added a commit
to checkedc/checkedc
that referenced
this pull request
Aug 19, 2018
This changes add tests for parsing and type checking of return_value expressions. This matches the compiler pull request at checkedc/checkedc-clang#544.
sulekhark
pushed a commit
that referenced
this pull request
Jul 8, 2021
This was referenced Jan 15, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The _Return_value expression allows programmers to name the value returned by a function in a return bounds declaration. This changes extends the clang IR to represent it and _Current_expr_value. It also adds lexing, parsing, and type system support for _Return_value. This addresses the first part of issue #205. Support for checking of bounds declarations using _Return_value will be implemented next.
We create a new expression class BoundsValueExpr to represent these expressions. This class is modelled on CXXThisExpr. Constructing a_Return_value expression requires knowing the return type of the function that the return bounds is associated with. We must have the _Return_value expression constructed before we can build the function type, since function types incorporate the return bounds expressions. Unfortunately, we don't know the function return type until the middle of GetFullTypeForDeclarator in SemaType.cpp. Because clang intertwines AST building, type checking, and other static semantic checking, we have to "defer parse" return bounds expressions. "Defer parse" means that the compiler recognize the tokens that make up a return bounds expression, saves them, and parses them later to build the IR for the return bounds expressions.
To allow parsing of the return bounds to happen in the middle of SemaType.cpp, we introduce a callback from semantic checking to the parser. This lets us preserve the interface between the two. We have to bring the parameters into scope, since they've already gone out of scope by the time GetFullTypeForDeclarator runs. We aren't the first people to have to do this. Other parsing phases such as parsing of attributes have to do this too.
After parsing the return bounds expression, we attach it to the declarator whose type is being constructed. This lets us get the line number information right for error messages involving redeclarations with conflicting return bounds. (Long explanation: memoization of function types also memoizes bounds expressions embedded in ty pes. It does this by ignoring line numbers and abstracting function parameters to parameter locations. The end result is that line numbers for expressions embedded in types are meaningless. Clang has a complicated mechanism for tracking source line information for types called TypeSourceInfo, but we haven't implemented support for embedded expressions in types and are not likely to anytime soon).
This change also contains some unrelated clean up:
Testing: