-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Constant Expressions inside of GCC' asm strings #131003
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8450816
[Clang][WIP] Constant Expressions inside of gcc'asm strings
cor3ntin 6e535f3
format
cor3ntin 8c67e65
Add parsing tests
cor3ntin 1d29506
add missing header
cor3ntin 6e50781
Sema Tests
cor3ntin 363f0b7
Add docs and has_extension support
cor3ntin 8f15264
Address Erich's feedback
cor3ntin 4ea32fc
format
cor3ntin 599affb
Codegen tests
cor3ntin 1ccea7f
cleanup non sense in EvaluateAsStringImpl
cor3ntin 98e0d6c
move test to correct folder
cor3ntin a1f727e
Add !srcloc for non string literal expressions
cor3ntin cad2cec
require target
cor3ntin b9ffe4c
Address Erich's feedback
cor3ntin d17ca80
fix docs
cor3ntin 328f93c
More docs
cor3ntin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3193,7 +3193,7 @@ class AsmStmt : public Stmt { | |
/// getOutputConstraint - Return the constraint string for the specified | ||
/// output operand. All output constraints are known to be non-empty (either | ||
/// '=' or '+'). | ||
StringRef getOutputConstraint(unsigned i) const; | ||
std::string getOutputConstraint(unsigned i) const; | ||
|
||
/// isOutputPlusConstraint - Return true if the specified output constraint | ||
/// is a "+" constraint (which is both an input and an output) or false if it | ||
|
@@ -3214,14 +3214,14 @@ class AsmStmt : public Stmt { | |
|
||
/// getInputConstraint - Return the specified input constraint. Unlike output | ||
/// constraints, these can be empty. | ||
StringRef getInputConstraint(unsigned i) const; | ||
std::string getInputConstraint(unsigned i) const; | ||
|
||
const Expr *getInputExpr(unsigned i) const; | ||
|
||
//===--- Other ---===// | ||
|
||
unsigned getNumClobbers() const { return NumClobbers; } | ||
StringRef getClobber(unsigned i) const; | ||
std::string getClobber(unsigned i) const; | ||
|
||
static bool classof(const Stmt *T) { | ||
return T->getStmtClass() == GCCAsmStmtClass || | ||
|
@@ -3302,21 +3302,20 @@ class GCCAsmStmt : public AsmStmt { | |
friend class ASTStmtReader; | ||
|
||
SourceLocation RParenLoc; | ||
StringLiteral *AsmStr; | ||
Expr *AsmStr; | ||
|
||
// FIXME: If we wanted to, we could allocate all of these in one big array. | ||
StringLiteral **Constraints = nullptr; | ||
StringLiteral **Clobbers = nullptr; | ||
Expr **Constraints = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another suggestion to add to the |
||
Expr **Clobbers = nullptr; | ||
IdentifierInfo **Names = nullptr; | ||
unsigned NumLabels = 0; | ||
|
||
public: | ||
GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, | ||
bool isvolatile, unsigned numoutputs, unsigned numinputs, | ||
IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, | ||
StringLiteral *asmstr, unsigned numclobbers, | ||
StringLiteral **clobbers, unsigned numlabels, | ||
SourceLocation rparenloc); | ||
IdentifierInfo **names, Expr **constraints, Expr **exprs, | ||
Expr *asmstr, unsigned numclobbers, Expr **clobbers, | ||
unsigned numlabels, SourceLocation rparenloc); | ||
|
||
/// Build an empty inline-assembly statement. | ||
explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {} | ||
|
@@ -3326,9 +3325,11 @@ class GCCAsmStmt : public AsmStmt { | |
|
||
//===--- Asm String Analysis ---===// | ||
|
||
const StringLiteral *getAsmString() const { return AsmStr; } | ||
StringLiteral *getAsmString() { return AsmStr; } | ||
void setAsmString(StringLiteral *E) { AsmStr = E; } | ||
const Expr *getAsmStringExpr() const { return AsmStr; } | ||
Expr *getAsmStringExpr() { return AsmStr; } | ||
void setAsmStringExpr(Expr *E) { AsmStr = E; } | ||
|
||
std::string getAsmString() const; | ||
|
||
/// AsmStringPiece - this is part of a decomposed asm string specification | ||
/// (for use with the AnalyzeAsmString function below). An asm string is | ||
|
@@ -3397,14 +3398,12 @@ class GCCAsmStmt : public AsmStmt { | |
return {}; | ||
} | ||
|
||
StringRef getOutputConstraint(unsigned i) const; | ||
std::string getOutputConstraint(unsigned i) const; | ||
|
||
const StringLiteral *getOutputConstraintLiteral(unsigned i) const { | ||
return Constraints[i]; | ||
} | ||
StringLiteral *getOutputConstraintLiteral(unsigned i) { | ||
const Expr *getOutputConstraintExpr(unsigned i) const { | ||
return Constraints[i]; | ||
} | ||
Expr *getOutputConstraintExpr(unsigned i) { return Constraints[i]; } | ||
|
||
Expr *getOutputExpr(unsigned i); | ||
|
||
|
@@ -3425,12 +3424,12 @@ class GCCAsmStmt : public AsmStmt { | |
return {}; | ||
} | ||
|
||
StringRef getInputConstraint(unsigned i) const; | ||
std::string getInputConstraint(unsigned i) const; | ||
|
||
const StringLiteral *getInputConstraintLiteral(unsigned i) const { | ||
const Expr *getInputConstraintExpr(unsigned i) const { | ||
return Constraints[i + NumOutputs]; | ||
} | ||
StringLiteral *getInputConstraintLiteral(unsigned i) { | ||
Expr *getInputConstraintExpr(unsigned i) { | ||
return Constraints[i + NumOutputs]; | ||
} | ||
|
||
|
@@ -3441,6 +3440,8 @@ class GCCAsmStmt : public AsmStmt { | |
return const_cast<GCCAsmStmt*>(this)->getInputExpr(i); | ||
} | ||
|
||
static std::string ExtractStringFromGCCAsmStmtComponent(const Expr *E); | ||
|
||
//===--- Labels ---===// | ||
|
||
bool isAsmGoto() const { | ||
|
@@ -3489,12 +3490,9 @@ class GCCAsmStmt : public AsmStmt { | |
private: | ||
void setOutputsAndInputsAndClobbers(const ASTContext &C, | ||
IdentifierInfo **Names, | ||
StringLiteral **Constraints, | ||
Stmt **Exprs, | ||
unsigned NumOutputs, | ||
unsigned NumInputs, | ||
unsigned NumLabels, | ||
StringLiteral **Clobbers, | ||
Expr **Constraints, Stmt **Exprs, | ||
unsigned NumOutputs, unsigned NumInputs, | ||
unsigned NumLabels, Expr **Clobbers, | ||
unsigned NumClobbers); | ||
|
||
public: | ||
|
@@ -3505,12 +3503,10 @@ class GCCAsmStmt : public AsmStmt { | |
/// This returns -1 if the operand name is invalid. | ||
int getNamedOperand(StringRef SymbolicName) const; | ||
|
||
StringRef getClobber(unsigned i) const; | ||
std::string getClobber(unsigned i) const; | ||
|
||
StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; } | ||
const StringLiteral *getClobberStringLiteral(unsigned i) const { | ||
return Clobbers[i]; | ||
} | ||
Expr *getClobberExpr(unsigned i) { return Clobbers[i]; } | ||
const Expr *getClobberExpr(unsigned i) const { return Clobbers[i]; } | ||
|
||
SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; } | ||
SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } | ||
|
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.