SemaStmtAsm.cpp revision e54cba1ec0b0e498ee67d200289035797932e714
1//===--- SemaStmtAsm.cpp - Semantic Analysis for Asm Statements -----------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements semantic analysis for inline asm statements. 11// 12//===----------------------------------------------------------------------===// 13 14#include "clang/Sema/SemaInternal.h" 15#include "clang/Sema/Scope.h" 16#include "clang/Sema/ScopeInfo.h" 17#include "clang/Sema/Initialization.h" 18#include "clang/Sema/Lookup.h" 19#include "clang/AST/TypeLoc.h" 20#include "clang/Lex/Preprocessor.h" 21#include "clang/Basic/TargetInfo.h" 22#include "llvm/ADT/ArrayRef.h" 23#include "llvm/ADT/BitVector.h" 24#include "llvm/ADT/SmallString.h" 25#include "llvm/MC/MCAsmInfo.h" 26#include "llvm/MC/MCContext.h" 27#include "llvm/MC/MCExpr.h" 28#include "llvm/MC/MCInst.h" 29#include "llvm/MC/MCInstPrinter.h" 30#include "llvm/MC/MCInstrInfo.h" 31#include "llvm/MC/MCObjectFileInfo.h" 32#include "llvm/MC/MCRegisterInfo.h" 33#include "llvm/MC/MCStreamer.h" 34#include "llvm/MC/MCSubtargetInfo.h" 35#include "llvm/MC/MCSymbol.h" 36#include "llvm/MC/MCTargetAsmParser.h" 37#include "llvm/MC/MCParser/MCAsmLexer.h" 38#include "llvm/MC/MCParser/MCAsmParser.h" 39#include "llvm/MC/MCParser/MCParsedAsmOperand.h" 40#include "llvm/Support/SourceMgr.h" 41#include "llvm/Support/TargetRegistry.h" 42#include "llvm/Support/TargetSelect.h" 43using namespace clang; 44using namespace sema; 45 46/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently 47/// ignore "noop" casts in places where an lvalue is required by an inline asm. 48/// We emulate this behavior when -fheinous-gnu-extensions is specified, but 49/// provide a strong guidance to not use it. 50/// 51/// This method checks to see if the argument is an acceptable l-value and 52/// returns false if it is a case we can handle. 53static bool CheckAsmLValue(const Expr *E, Sema &S) { 54 // Type dependent expressions will be checked during instantiation. 55 if (E->isTypeDependent()) 56 return false; 57 58 if (E->isLValue()) 59 return false; // Cool, this is an lvalue. 60 61 // Okay, this is not an lvalue, but perhaps it is the result of a cast that we 62 // are supposed to allow. 63 const Expr *E2 = E->IgnoreParenNoopCasts(S.Context); 64 if (E != E2 && E2->isLValue()) { 65 if (!S.getLangOpts().HeinousExtensions) 66 S.Diag(E2->getLocStart(), diag::err_invalid_asm_cast_lvalue) 67 << E->getSourceRange(); 68 else 69 S.Diag(E2->getLocStart(), diag::warn_invalid_asm_cast_lvalue) 70 << E->getSourceRange(); 71 // Accept, even if we emitted an error diagnostic. 72 return false; 73 } 74 75 // None of the above, just randomly invalid non-lvalue. 76 return true; 77} 78 79/// isOperandMentioned - Return true if the specified operand # is mentioned 80/// anywhere in the decomposed asm string. 81static bool isOperandMentioned(unsigned OpNo, 82 ArrayRef<GCCAsmStmt::AsmStringPiece> AsmStrPieces) { 83 for (unsigned p = 0, e = AsmStrPieces.size(); p != e; ++p) { 84 const GCCAsmStmt::AsmStringPiece &Piece = AsmStrPieces[p]; 85 if (!Piece.isOperand()) continue; 86 87 // If this is a reference to the input and if the input was the smaller 88 // one, then we have to reject this asm. 89 if (Piece.getOperandNo() == OpNo) 90 return true; 91 } 92 return false; 93} 94 95StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, 96 bool IsVolatile, unsigned NumOutputs, 97 unsigned NumInputs, IdentifierInfo **Names, 98 MultiExprArg constraints, MultiExprArg exprs, 99 Expr *asmString, MultiExprArg clobbers, 100 SourceLocation RParenLoc) { 101 unsigned NumClobbers = clobbers.size(); 102 StringLiteral **Constraints = 103 reinterpret_cast<StringLiteral**>(constraints.data()); 104 Expr **Exprs = exprs.data(); 105 StringLiteral *AsmString = cast<StringLiteral>(asmString); 106 StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.data()); 107 108 SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos; 109 110 // The parser verifies that there is a string literal here. 111 if (!AsmString->isAscii()) 112 return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character) 113 << AsmString->getSourceRange()); 114 115 for (unsigned i = 0; i != NumOutputs; i++) { 116 StringLiteral *Literal = Constraints[i]; 117 if (!Literal->isAscii()) 118 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) 119 << Literal->getSourceRange()); 120 121 StringRef OutputName; 122 if (Names[i]) 123 OutputName = Names[i]->getName(); 124 125 TargetInfo::ConstraintInfo Info(Literal->getString(), OutputName); 126 if (!Context.getTargetInfo().validateOutputConstraint(Info)) 127 return StmtError(Diag(Literal->getLocStart(), 128 diag::err_asm_invalid_output_constraint) 129 << Info.getConstraintStr()); 130 131 // Check that the output exprs are valid lvalues. 132 Expr *OutputExpr = Exprs[i]; 133 if (CheckAsmLValue(OutputExpr, *this)) { 134 return StmtError(Diag(OutputExpr->getLocStart(), 135 diag::err_asm_invalid_lvalue_in_output) 136 << OutputExpr->getSourceRange()); 137 } 138 139 OutputConstraintInfos.push_back(Info); 140 } 141 142 SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos; 143 144 for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) { 145 StringLiteral *Literal = Constraints[i]; 146 if (!Literal->isAscii()) 147 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) 148 << Literal->getSourceRange()); 149 150 StringRef InputName; 151 if (Names[i]) 152 InputName = Names[i]->getName(); 153 154 TargetInfo::ConstraintInfo Info(Literal->getString(), InputName); 155 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos.data(), 156 NumOutputs, Info)) { 157 return StmtError(Diag(Literal->getLocStart(), 158 diag::err_asm_invalid_input_constraint) 159 << Info.getConstraintStr()); 160 } 161 162 Expr *InputExpr = Exprs[i]; 163 164 // Only allow void types for memory constraints. 165 if (Info.allowsMemory() && !Info.allowsRegister()) { 166 if (CheckAsmLValue(InputExpr, *this)) 167 return StmtError(Diag(InputExpr->getLocStart(), 168 diag::err_asm_invalid_lvalue_in_input) 169 << Info.getConstraintStr() 170 << InputExpr->getSourceRange()); 171 } 172 173 if (Info.allowsRegister()) { 174 if (InputExpr->getType()->isVoidType()) { 175 return StmtError(Diag(InputExpr->getLocStart(), 176 diag::err_asm_invalid_type_in_input) 177 << InputExpr->getType() << Info.getConstraintStr() 178 << InputExpr->getSourceRange()); 179 } 180 } 181 182 ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]); 183 if (Result.isInvalid()) 184 return StmtError(); 185 186 Exprs[i] = Result.take(); 187 InputConstraintInfos.push_back(Info); 188 } 189 190 // Check that the clobbers are valid. 191 for (unsigned i = 0; i != NumClobbers; i++) { 192 StringLiteral *Literal = Clobbers[i]; 193 if (!Literal->isAscii()) 194 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) 195 << Literal->getSourceRange()); 196 197 StringRef Clobber = Literal->getString(); 198 199 if (!Context.getTargetInfo().isValidClobber(Clobber)) 200 return StmtError(Diag(Literal->getLocStart(), 201 diag::err_asm_unknown_register_name) << Clobber); 202 } 203 204 GCCAsmStmt *NS = 205 new (Context) GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, 206 NumInputs, Names, Constraints, Exprs, AsmString, 207 NumClobbers, Clobbers, RParenLoc); 208 // Validate the asm string, ensuring it makes sense given the operands we 209 // have. 210 SmallVector<GCCAsmStmt::AsmStringPiece, 8> Pieces; 211 unsigned DiagOffs; 212 if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) { 213 Diag(getLocationOfStringLiteralByte(AsmString, DiagOffs), DiagID) 214 << AsmString->getSourceRange(); 215 return StmtError(); 216 } 217 218 // Validate tied input operands for type mismatches. 219 for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) { 220 TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i]; 221 222 // If this is a tied constraint, verify that the output and input have 223 // either exactly the same type, or that they are int/ptr operands with the 224 // same size (int/long, int*/long, are ok etc). 225 if (!Info.hasTiedOperand()) continue; 226 227 unsigned TiedTo = Info.getTiedOperand(); 228 unsigned InputOpNo = i+NumOutputs; 229 Expr *OutputExpr = Exprs[TiedTo]; 230 Expr *InputExpr = Exprs[InputOpNo]; 231 232 if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent()) 233 continue; 234 235 QualType InTy = InputExpr->getType(); 236 QualType OutTy = OutputExpr->getType(); 237 if (Context.hasSameType(InTy, OutTy)) 238 continue; // All types can be tied to themselves. 239 240 // Decide if the input and output are in the same domain (integer/ptr or 241 // floating point. 242 enum AsmDomain { 243 AD_Int, AD_FP, AD_Other 244 } InputDomain, OutputDomain; 245 246 if (InTy->isIntegerType() || InTy->isPointerType()) 247 InputDomain = AD_Int; 248 else if (InTy->isRealFloatingType()) 249 InputDomain = AD_FP; 250 else 251 InputDomain = AD_Other; 252 253 if (OutTy->isIntegerType() || OutTy->isPointerType()) 254 OutputDomain = AD_Int; 255 else if (OutTy->isRealFloatingType()) 256 OutputDomain = AD_FP; 257 else 258 OutputDomain = AD_Other; 259 260 // They are ok if they are the same size and in the same domain. This 261 // allows tying things like: 262 // void* to int* 263 // void* to int if they are the same size. 264 // double to long double if they are the same size. 265 // 266 uint64_t OutSize = Context.getTypeSize(OutTy); 267 uint64_t InSize = Context.getTypeSize(InTy); 268 if (OutSize == InSize && InputDomain == OutputDomain && 269 InputDomain != AD_Other) 270 continue; 271 272 // If the smaller input/output operand is not mentioned in the asm string, 273 // then we can promote the smaller one to a larger input and the asm string 274 // won't notice. 275 bool SmallerValueMentioned = false; 276 277 // If this is a reference to the input and if the input was the smaller 278 // one, then we have to reject this asm. 279 if (isOperandMentioned(InputOpNo, Pieces)) { 280 // This is a use in the asm string of the smaller operand. Since we 281 // codegen this by promoting to a wider value, the asm will get printed 282 // "wrong". 283 SmallerValueMentioned |= InSize < OutSize; 284 } 285 if (isOperandMentioned(TiedTo, Pieces)) { 286 // If this is a reference to the output, and if the output is the larger 287 // value, then it's ok because we'll promote the input to the larger type. 288 SmallerValueMentioned |= OutSize < InSize; 289 } 290 291 // If the smaller value wasn't mentioned in the asm string, and if the 292 // output was a register, just extend the shorter one to the size of the 293 // larger one. 294 if (!SmallerValueMentioned && InputDomain != AD_Other && 295 OutputConstraintInfos[TiedTo].allowsRegister()) 296 continue; 297 298 // Either both of the operands were mentioned or the smaller one was 299 // mentioned. One more special case that we'll allow: if the tied input is 300 // integer, unmentioned, and is a constant, then we'll allow truncating it 301 // down to the size of the destination. 302 if (InputDomain == AD_Int && OutputDomain == AD_Int && 303 !isOperandMentioned(InputOpNo, Pieces) && 304 InputExpr->isEvaluatable(Context)) { 305 CastKind castKind = 306 (OutTy->isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast); 307 InputExpr = ImpCastExprToType(InputExpr, OutTy, castKind).take(); 308 Exprs[InputOpNo] = InputExpr; 309 NS->setInputExpr(i, InputExpr); 310 continue; 311 } 312 313 Diag(InputExpr->getLocStart(), 314 diag::err_asm_tying_incompatible_types) 315 << InTy << OutTy << OutputExpr->getSourceRange() 316 << InputExpr->getSourceRange(); 317 return StmtError(); 318 } 319 320 return Owned(NS); 321} 322 323// getSpelling - Get the spelling of the AsmTok token. 324static StringRef getSpelling(Sema &SemaRef, Token AsmTok) { 325 StringRef Asm; 326 SmallString<512> TokenBuf; 327 TokenBuf.resize(512); 328 bool StringInvalid = false; 329 Asm = SemaRef.PP.getSpelling(AsmTok, TokenBuf, &StringInvalid); 330 assert (!StringInvalid && "Expected valid string!"); 331 return Asm; 332} 333 334// Build the inline assembly string. Returns true on error. 335static bool buildMSAsmString(Sema &SemaRef, 336 SourceLocation AsmLoc, 337 ArrayRef<Token> AsmToks, 338 std::string &AsmString) { 339 assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!"); 340 341 SmallString<512> Asm; 342 for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) { 343 bool isNewAsm = ((i == 0) || 344 AsmToks[i].isAtStartOfLine() || 345 AsmToks[i].is(tok::kw_asm)); 346 if (isNewAsm) { 347 if (i != 0) 348 Asm += "\n\t"; 349 350 if (AsmToks[i].is(tok::kw_asm)) { 351 i++; // Skip __asm 352 if (i == e) { 353 SemaRef.Diag(AsmLoc, diag::err_asm_empty); 354 return true; 355 } 356 357 } 358 } 359 360 if (i && AsmToks[i].hasLeadingSpace() && !isNewAsm) 361 Asm += ' '; 362 363 StringRef Spelling = getSpelling(SemaRef, AsmToks[i]); 364 Asm += Spelling; 365 } 366 AsmString = Asm.str(); 367 return false; 368} 369 370namespace { 371enum AsmOpRewriteKind { 372 AOK_Imm, 373 AOK_Input, 374 AOK_Output 375}; 376 377struct AsmOpRewrite { 378 AsmOpRewriteKind Kind; 379 llvm::SMLoc Loc; 380 unsigned Len; 381 382public: 383 AsmOpRewrite(AsmOpRewriteKind kind, llvm::SMLoc loc, unsigned len) 384 : Kind(kind), Loc(loc), Len(len) { } 385}; 386 387} 388 389StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, 390 ArrayRef<Token> AsmToks,SourceLocation EndLoc) { 391 SmallVector<IdentifierInfo*, 4> Inputs; 392 SmallVector<IdentifierInfo*, 4> Outputs; 393 SmallVector<IdentifierInfo*, 4> Names; 394 SmallVector<std::string, 4> InputConstraints; 395 SmallVector<std::string, 4> OutputConstraints; 396 SmallVector<StringRef, 4> Constraints; 397 unsigned NumOutputs; 398 unsigned NumInputs; 399 SmallVector<Expr*, 4> InputExprs; 400 SmallVector<Expr*, 4> OutputExprs; 401 SmallVector<Expr*, 4> Exprs; 402 SmallVector<StringRef, 4> Clobbers; 403 std::set<std::string> ClobberRegs; 404 405 SmallVector<struct AsmOpRewrite, 4> AsmStrRewrites; 406 407 // Empty asm statements don't need to instantiate the AsmParser, etc. 408 if (AsmToks.empty()) { 409 StringRef EmptyAsmStr; 410 MSAsmStmt *NS = 411 new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ true, 412 /*IsVolatile*/ true, AsmToks, /*NumOutputs*/ 0, 413 /*NumInputs*/ 0, Names, Constraints, Exprs, EmptyAsmStr, 414 Clobbers, EndLoc); 415 return Owned(NS); 416 } 417 418 std::string AsmString; 419 if (buildMSAsmString(*this, AsmLoc, AsmToks, AsmString)) 420 return StmtError(); 421 422 // Get the target specific parser. 423 std::string Error; 424 const std::string &TT = Context.getTargetInfo().getTriple().getTriple(); 425 const llvm::Target *TheTarget(llvm::TargetRegistry::lookupTarget(TT, Error)); 426 427 OwningPtr<llvm::MCAsmInfo> MAI(TheTarget->createMCAsmInfo(TT)); 428 OwningPtr<llvm::MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT)); 429 OwningPtr<llvm::MCObjectFileInfo> MOFI(new llvm::MCObjectFileInfo()); 430 OwningPtr<llvm::MCSubtargetInfo> 431 STI(TheTarget->createMCSubtargetInfo(TT, "", "")); 432 433 llvm::SourceMgr SrcMgr; 434 llvm::MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr); 435 llvm::MemoryBuffer *Buffer = 436 llvm::MemoryBuffer::getMemBuffer(AsmString, "<inline asm>"); 437 438 // Tell SrcMgr about this buffer, which is what the parser will pick up. 439 SrcMgr.AddNewSourceBuffer(Buffer, llvm::SMLoc()); 440 441 OwningPtr<llvm::MCStreamer> Str(createNullStreamer(Ctx)); 442 OwningPtr<llvm::MCAsmParser> 443 Parser(createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI)); 444 OwningPtr<llvm::MCTargetAsmParser> 445 TargetParser(TheTarget->createMCAsmParser(*STI, *Parser)); 446 Parser->setParsingInlineAsm(true); 447 448 // Get the instruction descriptor. 449 const llvm::MCInstrInfo *MII = TheTarget->createMCInstrInfo(); 450 llvm::MCInstPrinter *IP = 451 TheTarget->createMCInstPrinter(1, *MAI, *MII, *MRI, *STI); 452 453 // Change to the Intel dialect. 454 Parser->setAssemblerDialect(1); 455 Parser->setTargetParser(*TargetParser.get()); 456 Parser->setParsingInlineAsm(true); 457 458 // Prime the lexer. 459 Parser->Lex(); 460 461 // While we have input, parse each statement. 462 unsigned InputIdx = 0; 463 unsigned OutputIdx = 0; 464 while (Parser->getLexer().isNot(llvm::AsmToken::Eof)) { 465 if (Parser->ParseStatement()) { 466 // FIXME: The AsmParser should report errors, but we could potentially be 467 // more verbose here. 468 break; 469 } 470 471 if (Parser->isInstruction()) { 472 const llvm::MCInstrDesc &Desc = MII->get(Parser->getOpcode()); 473 474 // Build the list of clobbers, outputs and inputs. 475 for (unsigned i = 1, e = Parser->getNumParsedOperands(); i != e; ++i) { 476 llvm::MCParsedAsmOperand &Operand = Parser->getParsedOperand(i); 477 478 // Immediate. 479 if (Operand.isImm()) { 480 AsmStrRewrites.push_back(AsmOpRewrite(AOK_Imm, 481 Operand.getStartLoc(), 482 Operand.getNameLen())); 483 continue; 484 } 485 486 487 // Register operand. 488 if (Operand.isReg()) { 489 unsigned NumDefs = Desc.getNumDefs(); 490 // Clobber. 491 if (NumDefs && Operand.getMCOperandNum() < NumDefs) { 492 std::string Reg; 493 llvm::raw_string_ostream OS(Reg); 494 IP->printRegName(OS, Operand.getReg()); 495 StringRef Clobber(OS.str()); 496 if (!Context.getTargetInfo().isValidClobber(Clobber)) 497 return StmtError( 498 Diag(AsmLoc, diag::err_asm_unknown_register_name) << Clobber); 499 ClobberRegs.insert(Reg); 500 } 501 continue; 502 } 503 504 505 // Expr/Input or Output. 506 StringRef Name = Operand.getName(); 507 if (IdentifierInfo *II = &Context.Idents.get(Name)) { 508 CXXScopeSpec SS; 509 UnqualifiedId Id; 510 SourceLocation Loc; 511 Id.setIdentifier(II, AsmLoc); 512 ExprResult Result = ActOnIdExpression(getCurScope(), SS, Loc, Id, 513 false, false); 514 if (!Result.isInvalid()) { 515 bool isOutput = (i == 1) && Desc.mayStore(); 516 if (isOutput) { 517 std::string Constraint = "="; 518 ++InputIdx; 519 Outputs.push_back(II); 520 OutputExprs.push_back(Result.take()); 521 Constraint += Operand.getConstraint().str(); 522 OutputConstraints.push_back(Constraint); 523 AsmStrRewrites.push_back(AsmOpRewrite(AOK_Output, 524 Operand.getStartLoc(), 525 Operand.getNameLen())); 526 } else { 527 Inputs.push_back(II); 528 InputExprs.push_back(Result.take()); 529 InputConstraints.push_back(Operand.getConstraint().str()); 530 AsmStrRewrites.push_back(AsmOpRewrite(AOK_Input, 531 Operand.getStartLoc(), 532 Operand.getNameLen())); 533 } 534 } 535 } 536 } 537 Parser->freeParsedOperands(); 538 } 539 } 540 541 // Set the number of Outputs and Inputs. 542 NumOutputs = Outputs.size(); 543 NumInputs = Inputs.size(); 544 545 // Set the unique clobbers. 546 for (std::set<std::string>::iterator I = ClobberRegs.begin(), 547 E = ClobberRegs.end(); I != E; ++I) 548 Clobbers.push_back(*I); 549 550 // Merge the various outputs and inputs. Output are expected first. 551 Names.resize(NumOutputs + NumInputs); 552 Constraints.resize(NumOutputs + NumInputs); 553 Exprs.resize(NumOutputs + NumInputs); 554 for (unsigned i = 0; i < NumOutputs; ++i) { 555 Names[i] = Outputs[i]; 556 Constraints[i] = OutputConstraints[i]; 557 Exprs[i] = OutputExprs[i]; 558 } 559 for (unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) { 560 Names[j] = Inputs[i]; 561 Constraints[j] = InputConstraints[i]; 562 Exprs[j] = InputExprs[i]; 563 } 564 565 // Build the IR assembly string. 566 std::string AsmStringIR; 567 llvm::raw_string_ostream OS(AsmStringIR); 568 const char *Start = AsmString.c_str(); 569 for (SmallVectorImpl<struct AsmOpRewrite>::iterator I = AsmStrRewrites.begin(), 570 E = AsmStrRewrites.end(); I != E; ++I) { 571 const char *Loc = (*I).Loc.getPointer(); 572 573 // Emit everything up to the immediate/expression. 574 OS << StringRef(Start, Loc - Start); 575 576 // Rewrite expressions in $N notation. 577 switch ((*I).Kind) { 578 case AOK_Imm: 579 OS << Twine("$$") + StringRef(Loc, (*I).Len); 580 break; 581 case AOK_Input: 582 OS << '$'; 583 OS << InputIdx++; 584 break; 585 case AOK_Output: 586 OS << '$'; 587 OS << OutputIdx++; 588 break; 589 } 590 591 // Skip the original expression. 592 Start = Loc + (*I).Len; 593 } 594 // Emit the remainder of the asm string. 595 const char *AsmEnd = AsmString.c_str() + AsmString.size(); 596 if (Start != AsmEnd) 597 OS << StringRef(Start, AsmEnd - Start); 598 599 AsmString = OS.str(); 600 MSAsmStmt *NS = 601 new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ true, 602 /*IsVolatile*/ true, AsmToks, NumOutputs, 603 NumInputs, Names, Constraints, Exprs, AsmString, 604 Clobbers, EndLoc); 605 return Owned(NS); 606} 607