summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorMatan Haroush <matan.haroush@intel.com>2017-07-25 10:43:43 +0000
committerMatan Haroush <matan.haroush@intel.com>2017-07-25 10:43:43 +0000
commitb4b8d1035565817fa083d16700d92b0053490dd4 (patch)
treea0502ef3316735bbf9ea757bf61a80884afb7235 /clang/lib
parentcd2255ea6a92b3601bca5aef7086e740cdb020ae (diff)
downloadbcm5719-llvm-b4b8d1035565817fa083d16700d92b0053490dd4.tar.gz
bcm5719-llvm-b4b8d1035565817fa083d16700d92b0053490dd4.zip
This patch enables the usage of constant Enum identifiers within Microsoft style inline assembly statements.
Differential Revision: https://reviews.llvm.org/D33277 https://reviews.llvm.org/D33278 llvm-svn: 308965
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaStmtAsm.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index c182b35bfad..a6008056590 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -645,8 +645,8 @@ ExprResult Sema::LookupInlineAsmIdentifier(CXXScopeSpec &SS,
// Referring to parameters is not allowed in naked functions.
if (CheckNakedParmReference(Result.get(), *this))
return ExprError();
-
- QualType T = Result.get()->getType();
+ Expr *Res = Result.get();
+ QualType T = Res->getType();
if (T->isDependentType()) {
return Result;
@@ -658,16 +658,26 @@ ExprResult Sema::LookupInlineAsmIdentifier(CXXScopeSpec &SS,
}
// Otherwise, it needs to be a complete type.
- if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
+ if (RequireCompleteExprType(Res, diag::err_asm_incomplete_type)) {
return ExprError();
}
fillInlineAsmTypeInfo(Context, T, Info);
// We can work with the expression as long as it's not an r-value.
- if (!Result.get()->isRValue())
- Info.IsVarDecl = true;
+ if (!Res->isRValue()) {
+ Info.setKindVariable();
+ return Result;
+ }
+ Expr::EvalResult EvlResult;
+ // Try to evaluate the identifier as enum constant, currently we do not allow
+ // other constant integers to be folded.
+ if (isa<clang::EnumType>(T) &&
+ Res->EvaluateAsRValue(EvlResult, getASTContext())) {
+ Info.ConstIntValue = EvlResult.Val.getInt();
+ Info.setKindConstEnum();
+ }
return Result;
}
@@ -774,7 +784,7 @@ Sema::LookupInlineAsmVarDeclField(Expr *E, StringRef Member,
fillInlineAsmTypeInfo(Context, Result.get()->getType(), Info);
// Fields are "variables" as far as inline assembly is concerned.
- Info.IsVarDecl = true;
+ Info.setKindVariable();
return Result;
}
OpenPOWER on IntegriCloud