From b4b8d1035565817fa083d16700d92b0053490dd4 Mon Sep 17 00:00:00 2001 From: Matan Haroush Date: Tue, 25 Jul 2017 10:43:43 +0000 Subject: 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 --- clang/lib/Sema/SemaStmtAsm.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'clang/lib') 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(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; } -- cgit v1.2.3