clang  10.0.0svn
SemaStmtAsm.cpp
Go to the documentation of this file.
1 //===--- SemaStmtAsm.cpp - Semantic Analysis for Asm Statements -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements semantic analysis for inline asm statements.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/AST/ExprCXX.h"
14 #include "clang/AST/RecordLayout.h"
15 #include "clang/AST/TypeLoc.h"
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Lex/Preprocessor.h"
19 #include "clang/Sema/Lookup.h"
20 #include "clang/Sema/Scope.h"
21 #include "clang/Sema/ScopeInfo.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/StringSet.h"
25 #include "llvm/MC/MCParser/MCAsmParser.h"
26 using namespace clang;
27 using namespace sema;
28 
29 /// Remove the upper-level LValueToRValue cast from an expression.
30 static void removeLValueToRValueCast(Expr *E) {
31  Expr *Parent = E;
32  Expr *ExprUnderCast = nullptr;
33  SmallVector<Expr *, 8> ParentsToUpdate;
34 
35  while (true) {
36  ParentsToUpdate.push_back(Parent);
37  if (auto *ParenE = dyn_cast<ParenExpr>(Parent)) {
38  Parent = ParenE->getSubExpr();
39  continue;
40  }
41 
42  Expr *Child = nullptr;
43  CastExpr *ParentCast = dyn_cast<CastExpr>(Parent);
44  if (ParentCast)
45  Child = ParentCast->getSubExpr();
46  else
47  return;
48 
49  if (auto *CastE = dyn_cast<CastExpr>(Child))
50  if (CastE->getCastKind() == CK_LValueToRValue) {
51  ExprUnderCast = CastE->getSubExpr();
52  // LValueToRValue cast inside GCCAsmStmt requires an explicit cast.
53  ParentCast->setSubExpr(ExprUnderCast);
54  break;
55  }
56  Parent = Child;
57  }
58 
59  // Update parent expressions to have same ValueType as the underlying.
60  assert(ExprUnderCast &&
61  "Should be reachable only if LValueToRValue cast was found!");
62  auto ValueKind = ExprUnderCast->getValueKind();
63  for (Expr *E : ParentsToUpdate)
64  E->setValueKind(ValueKind);
65 }
66 
67 /// Emit a warning about usage of "noop"-like casts for lvalues (GNU extension)
68 /// and fix the argument with removing LValueToRValue cast from the expression.
69 static void emitAndFixInvalidAsmCastLValue(const Expr *LVal, Expr *BadArgument,
70  Sema &S) {
71  if (!S.getLangOpts().HeinousExtensions) {
72  S.Diag(LVal->getBeginLoc(), diag::err_invalid_asm_cast_lvalue)
73  << BadArgument->getSourceRange();
74  } else {
75  S.Diag(LVal->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
76  << BadArgument->getSourceRange();
77  }
78  removeLValueToRValueCast(BadArgument);
79 }
80 
81 /// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently
82 /// ignore "noop" casts in places where an lvalue is required by an inline asm.
83 /// We emulate this behavior when -fheinous-gnu-extensions is specified, but
84 /// provide a strong guidance to not use it.
85 ///
86 /// This method checks to see if the argument is an acceptable l-value and
87 /// returns false if it is a case we can handle.
88 static bool CheckAsmLValue(Expr *E, Sema &S) {
89  // Type dependent expressions will be checked during instantiation.
90  if (E->isTypeDependent())
91  return false;
92 
93  if (E->isLValue())
94  return false; // Cool, this is an lvalue.
95 
96  // Okay, this is not an lvalue, but perhaps it is the result of a cast that we
97  // are supposed to allow.
98  const Expr *E2 = E->IgnoreParenNoopCasts(S.Context);
99  if (E != E2 && E2->isLValue()) {
101  // Accept, even if we emitted an error diagnostic.
102  return false;
103  }
104 
105  // None of the above, just randomly invalid non-lvalue.
106  return true;
107 }
108 
109 /// isOperandMentioned - Return true if the specified operand # is mentioned
110 /// anywhere in the decomposed asm string.
111 static bool
112 isOperandMentioned(unsigned OpNo,
114  for (unsigned p = 0, e = AsmStrPieces.size(); p != e; ++p) {
115  const GCCAsmStmt::AsmStringPiece &Piece = AsmStrPieces[p];
116  if (!Piece.isOperand())
117  continue;
118 
119  // If this is a reference to the input and if the input was the smaller
120  // one, then we have to reject this asm.
121  if (Piece.getOperandNo() == OpNo)
122  return true;
123  }
124  return false;
125 }
126 
127 static bool CheckNakedParmReference(Expr *E, Sema &S) {
128  FunctionDecl *Func = dyn_cast<FunctionDecl>(S.CurContext);
129  if (!Func)
130  return false;
131  if (!Func->hasAttr<NakedAttr>())
132  return false;
133 
134  SmallVector<Expr*, 4> WorkList;
135  WorkList.push_back(E);
136  while (WorkList.size()) {
137  Expr *E = WorkList.pop_back_val();
138  if (isa<CXXThisExpr>(E)) {
139  S.Diag(E->getBeginLoc(), diag::err_asm_naked_this_ref);
140  S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
141  return true;
142  }
143  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
144  if (isa<ParmVarDecl>(DRE->getDecl())) {
145  S.Diag(DRE->getBeginLoc(), diag::err_asm_naked_parm_ref);
146  S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
147  return true;
148  }
149  }
150  for (Stmt *Child : E->children()) {
151  if (Expr *E = dyn_cast_or_null<Expr>(Child))
152  WorkList.push_back(E);
153  }
154  }
155  return false;
156 }
157 
158 /// Returns true if given expression is not compatible with inline
159 /// assembly's memory constraint; false otherwise.
162  bool is_input_expr) {
163  enum {
164  ExprBitfield = 0,
165  ExprVectorElt,
166  ExprGlobalRegVar,
167  ExprSafeType
168  } EType = ExprSafeType;
169 
170  // Bitfields, vector elements and global register variables are not
171  // compatible.
172  if (E->refersToBitField())
173  EType = ExprBitfield;
174  else if (E->refersToVectorElement())
175  EType = ExprVectorElt;
176  else if (E->refersToGlobalRegisterVar())
177  EType = ExprGlobalRegVar;
178 
179  if (EType != ExprSafeType) {
180  S.Diag(E->getBeginLoc(), diag::err_asm_non_addr_value_in_memory_constraint)
181  << EType << is_input_expr << Info.getConstraintStr()
182  << E->getSourceRange();
183  return true;
184  }
185 
186  return false;
187 }
188 
189 // Extracting the register name from the Expression value,
190 // if there is no register name to extract, returns ""
191 static StringRef extractRegisterName(const Expr *Expression,
192  const TargetInfo &Target) {
193  Expression = Expression->IgnoreImpCasts();
194  if (const DeclRefExpr *AsmDeclRef = dyn_cast<DeclRefExpr>(Expression)) {
195  // Handle cases where the expression is a variable
196  const VarDecl *Variable = dyn_cast<VarDecl>(AsmDeclRef->getDecl());
197  if (Variable && Variable->getStorageClass() == SC_Register) {
198  if (AsmLabelAttr *Attr = Variable->getAttr<AsmLabelAttr>())
199  if (Target.isValidGCCRegisterName(Attr->getLabel()))
200  return Target.getNormalizedGCCRegisterName(Attr->getLabel(), true);
201  }
202  }
203  return "";
204 }
205 
206 // Checks if there is a conflict between the input and output lists with the
207 // clobbers list. If there's a conflict, returns the location of the
208 // conflicted clobber, else returns nullptr
209 static SourceLocation
211  StringLiteral **Clobbers, int NumClobbers,
212  unsigned NumLabels,
213  const TargetInfo &Target, ASTContext &Cont) {
214  llvm::StringSet<> InOutVars;
215  // Collect all the input and output registers from the extended asm
216  // statement in order to check for conflicts with the clobber list
217  for (unsigned int i = 0; i < Exprs.size() - NumLabels; ++i) {
218  StringRef Constraint = Constraints[i]->getString();
219  StringRef InOutReg = Target.getConstraintRegister(
220  Constraint, extractRegisterName(Exprs[i], Target));
221  if (InOutReg != "")
222  InOutVars.insert(InOutReg);
223  }
224  // Check for each item in the clobber list if it conflicts with the input
225  // or output
226  for (int i = 0; i < NumClobbers; ++i) {
227  StringRef Clobber = Clobbers[i]->getString();
228  // We only check registers, therefore we don't check cc and memory
229  // clobbers
230  if (Clobber == "cc" || Clobber == "memory")
231  continue;
232  Clobber = Target.getNormalizedGCCRegisterName(Clobber, true);
233  // Go over the output's registers we collected
234  if (InOutVars.count(Clobber))
235  return Clobbers[i]->getBeginLoc();
236  }
237  return SourceLocation();
238 }
239 
241  bool IsVolatile, unsigned NumOutputs,
242  unsigned NumInputs, IdentifierInfo **Names,
243  MultiExprArg constraints, MultiExprArg Exprs,
244  Expr *asmString, MultiExprArg clobbers,
245  unsigned NumLabels,
246  SourceLocation RParenLoc) {
247  unsigned NumClobbers = clobbers.size();
248  StringLiteral **Constraints =
249  reinterpret_cast<StringLiteral**>(constraints.data());
250  StringLiteral *AsmString = cast<StringLiteral>(asmString);
251  StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.data());
252 
253  SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
254 
255  // The parser verifies that there is a string literal here.
256  assert(AsmString->isAscii());
257 
258  for (unsigned i = 0; i != NumOutputs; i++) {
259  StringLiteral *Literal = Constraints[i];
260  assert(Literal->isAscii());
261 
262  StringRef OutputName;
263  if (Names[i])
264  OutputName = Names[i]->getName();
265 
266  TargetInfo::ConstraintInfo Info(Literal->getString(), OutputName);
267  if (!Context.getTargetInfo().validateOutputConstraint(Info)) {
268  targetDiag(Literal->getBeginLoc(),
269  diag::err_asm_invalid_output_constraint)
270  << Info.getConstraintStr();
271  return new (Context)
272  GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
273  NumInputs, Names, Constraints, Exprs.data(), AsmString,
274  NumClobbers, Clobbers, NumLabels, RParenLoc);
275  }
276 
277  ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
278  if (ER.isInvalid())
279  return StmtError();
280  Exprs[i] = ER.get();
281 
282  // Check that the output exprs are valid lvalues.
283  Expr *OutputExpr = Exprs[i];
284 
285  // Referring to parameters is not allowed in naked functions.
286  if (CheckNakedParmReference(OutputExpr, *this))
287  return StmtError();
288 
289  // Check that the output expression is compatible with memory constraint.
290  if (Info.allowsMemory() &&
291  checkExprMemoryConstraintCompat(*this, OutputExpr, Info, false))
292  return StmtError();
293 
294  OutputConstraintInfos.push_back(Info);
295 
296  // If this is dependent, just continue.
297  if (OutputExpr->isTypeDependent())
298  continue;
299 
301  OutputExpr->isModifiableLvalue(Context, /*Loc=*/nullptr);
302  switch (IsLV) {
303  case Expr::MLV_Valid:
304  // Cool, this is an lvalue.
305  break;
306  case Expr::MLV_ArrayType:
307  // This is OK too.
308  break;
309  case Expr::MLV_LValueCast: {
310  const Expr *LVal = OutputExpr->IgnoreParenNoopCasts(Context);
311  emitAndFixInvalidAsmCastLValue(LVal, OutputExpr, *this);
312  // Accept, even if we emitted an error diagnostic.
313  break;
314  }
317  if (RequireCompleteType(OutputExpr->getBeginLoc(), Exprs[i]->getType(),
318  diag::err_dereference_incomplete_type))
319  return StmtError();
320  LLVM_FALLTHROUGH;
321  default:
322  return StmtError(Diag(OutputExpr->getBeginLoc(),
323  diag::err_asm_invalid_lvalue_in_output)
324  << OutputExpr->getSourceRange());
325  }
326 
327  unsigned Size = Context.getTypeSize(OutputExpr->getType());
328  if (!Context.getTargetInfo().validateOutputSize(Literal->getString(),
329  Size)) {
330  targetDiag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_output_size)
331  << Info.getConstraintStr();
332  return new (Context)
333  GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
334  NumInputs, Names, Constraints, Exprs.data(), AsmString,
335  NumClobbers, Clobbers, NumLabels, RParenLoc);
336  }
337  }
338 
339  SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
340 
341  for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
342  StringLiteral *Literal = Constraints[i];
343  assert(Literal->isAscii());
344 
345  StringRef InputName;
346  if (Names[i])
347  InputName = Names[i]->getName();
348 
349  TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
350  if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
351  Info)) {
352  targetDiag(Literal->getBeginLoc(), diag::err_asm_invalid_input_constraint)
353  << Info.getConstraintStr();
354  return new (Context)
355  GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
356  NumInputs, Names, Constraints, Exprs.data(), AsmString,
357  NumClobbers, Clobbers, NumLabels, RParenLoc);
358  }
359 
360  ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
361  if (ER.isInvalid())
362  return StmtError();
363  Exprs[i] = ER.get();
364 
365  Expr *InputExpr = Exprs[i];
366 
367  // Referring to parameters is not allowed in naked functions.
368  if (CheckNakedParmReference(InputExpr, *this))
369  return StmtError();
370 
371  // Check that the input expression is compatible with memory constraint.
372  if (Info.allowsMemory() &&
373  checkExprMemoryConstraintCompat(*this, InputExpr, Info, true))
374  return StmtError();
375 
376  // Only allow void types for memory constraints.
377  if (Info.allowsMemory() && !Info.allowsRegister()) {
378  if (CheckAsmLValue(InputExpr, *this))
379  return StmtError(Diag(InputExpr->getBeginLoc(),
380  diag::err_asm_invalid_lvalue_in_input)
381  << Info.getConstraintStr()
382  << InputExpr->getSourceRange());
383  } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
384  if (!InputExpr->isValueDependent()) {
385  Expr::EvalResult EVResult;
386  if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
387  return StmtError(
388  Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
389  << Info.getConstraintStr() << InputExpr->getSourceRange());
390 
391  // For compatibility with GCC, we also allow pointers that would be
392  // integral constant expressions if they were cast to int.
393  llvm::APSInt IntResult;
394  if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
395  Context))
396  return StmtError(
397  Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
398  << Info.getConstraintStr() << InputExpr->getSourceRange());
399 
400  if (!Info.isValidAsmImmediate(IntResult))
401  return StmtError(Diag(InputExpr->getBeginLoc(),
402  diag::err_invalid_asm_value_for_constraint)
403  << IntResult.toString(10) << Info.getConstraintStr()
404  << InputExpr->getSourceRange());
405  }
406 
407  } else {
408  ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
409  if (Result.isInvalid())
410  return StmtError();
411 
412  Exprs[i] = Result.get();
413  }
414 
415  if (Info.allowsRegister()) {
416  if (InputExpr->getType()->isVoidType()) {
417  return StmtError(
418  Diag(InputExpr->getBeginLoc(), diag::err_asm_invalid_type_in_input)
419  << InputExpr->getType() << Info.getConstraintStr()
420  << InputExpr->getSourceRange());
421  }
422  }
423 
424  InputConstraintInfos.push_back(Info);
425 
426  const Type *Ty = Exprs[i]->getType().getTypePtr();
427  if (Ty->isDependentType())
428  continue;
429 
430  if (!Ty->isVoidType() || !Info.allowsMemory())
431  if (RequireCompleteType(InputExpr->getBeginLoc(), Exprs[i]->getType(),
432  diag::err_dereference_incomplete_type))
433  return StmtError();
434 
435  unsigned Size = Context.getTypeSize(Ty);
436  if (!Context.getTargetInfo().validateInputSize(Literal->getString(),
437  Size))
438  return StmtResult(
439  targetDiag(InputExpr->getBeginLoc(), diag::err_asm_invalid_input_size)
440  << Info.getConstraintStr());
441  }
442 
443  // Check that the clobbers are valid.
444  for (unsigned i = 0; i != NumClobbers; i++) {
445  StringLiteral *Literal = Clobbers[i];
446  assert(Literal->isAscii());
447 
448  StringRef Clobber = Literal->getString();
449 
450  if (!Context.getTargetInfo().isValidClobber(Clobber)) {
451  targetDiag(Literal->getBeginLoc(), diag::err_asm_unknown_register_name)
452  << Clobber;
453  return new (Context)
454  GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
455  NumInputs, Names, Constraints, Exprs.data(), AsmString,
456  NumClobbers, Clobbers, NumLabels, RParenLoc);
457  }
458  }
459 
460  GCCAsmStmt *NS =
461  new (Context) GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
462  NumInputs, Names, Constraints, Exprs.data(),
463  AsmString, NumClobbers, Clobbers, NumLabels,
464  RParenLoc);
465  // Validate the asm string, ensuring it makes sense given the operands we
466  // have.
468  unsigned DiagOffs;
469  if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) {
470  targetDiag(getLocationOfStringLiteralByte(AsmString, DiagOffs), DiagID)
471  << AsmString->getSourceRange();
472  return NS;
473  }
474 
475  // Validate constraints and modifiers.
476  for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
477  GCCAsmStmt::AsmStringPiece &Piece = Pieces[i];
478  if (!Piece.isOperand()) continue;
479 
480  // Look for the correct constraint index.
481  unsigned ConstraintIdx = Piece.getOperandNo();
482  // Labels are the last in the Exprs list.
483  if (NS->isAsmGoto() && ConstraintIdx >= NS->getNumInputs())
484  continue;
485  unsigned NumOperands = NS->getNumOutputs() + NS->getNumInputs();
486  // Look for the (ConstraintIdx - NumOperands + 1)th constraint with
487  // modifier '+'.
488  if (ConstraintIdx >= NumOperands) {
489  unsigned I = 0, E = NS->getNumOutputs();
490 
491  for (unsigned Cnt = ConstraintIdx - NumOperands; I != E; ++I)
492  if (OutputConstraintInfos[I].isReadWrite() && Cnt-- == 0) {
493  ConstraintIdx = I;
494  break;
495  }
496 
497  assert(I != E && "Invalid operand number should have been caught in "
498  " AnalyzeAsmString");
499  }
500 
501  // Now that we have the right indexes go ahead and check.
502  StringLiteral *Literal = Constraints[ConstraintIdx];
503  const Type *Ty = Exprs[ConstraintIdx]->getType().getTypePtr();
504  if (Ty->isDependentType() || Ty->isIncompleteType())
505  continue;
506 
507  unsigned Size = Context.getTypeSize(Ty);
508  std::string SuggestedModifier;
510  Literal->getString(), Piece.getModifier(), Size,
511  SuggestedModifier)) {
512  targetDiag(Exprs[ConstraintIdx]->getBeginLoc(),
513  diag::warn_asm_mismatched_size_modifier);
514 
515  if (!SuggestedModifier.empty()) {
516  auto B = targetDiag(Piece.getRange().getBegin(),
517  diag::note_asm_missing_constraint_modifier)
518  << SuggestedModifier;
519  SuggestedModifier = "%" + SuggestedModifier + Piece.getString();
520  B << FixItHint::CreateReplacement(Piece.getRange(), SuggestedModifier);
521  }
522  }
523  }
524 
525  // Validate tied input operands for type mismatches.
526  unsigned NumAlternatives = ~0U;
527  for (unsigned i = 0, e = OutputConstraintInfos.size(); i != e; ++i) {
528  TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
529  StringRef ConstraintStr = Info.getConstraintStr();
530  unsigned AltCount = ConstraintStr.count(',') + 1;
531  if (NumAlternatives == ~0U) {
532  NumAlternatives = AltCount;
533  } else if (NumAlternatives != AltCount) {
534  targetDiag(NS->getOutputExpr(i)->getBeginLoc(),
535  diag::err_asm_unexpected_constraint_alternatives)
536  << NumAlternatives << AltCount;
537  return NS;
538  }
539  }
540  SmallVector<size_t, 4> InputMatchedToOutput(OutputConstraintInfos.size(),
541  ~0U);
542  for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
543  TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
544  StringRef ConstraintStr = Info.getConstraintStr();
545  unsigned AltCount = ConstraintStr.count(',') + 1;
546  if (NumAlternatives == ~0U) {
547  NumAlternatives = AltCount;
548  } else if (NumAlternatives != AltCount) {
549  targetDiag(NS->getInputExpr(i)->getBeginLoc(),
550  diag::err_asm_unexpected_constraint_alternatives)
551  << NumAlternatives << AltCount;
552  return NS;
553  }
554 
555  // If this is a tied constraint, verify that the output and input have
556  // either exactly the same type, or that they are int/ptr operands with the
557  // same size (int/long, int*/long, are ok etc).
558  if (!Info.hasTiedOperand()) continue;
559 
560  unsigned TiedTo = Info.getTiedOperand();
561  unsigned InputOpNo = i+NumOutputs;
562  Expr *OutputExpr = Exprs[TiedTo];
563  Expr *InputExpr = Exprs[InputOpNo];
564 
565  // Make sure no more than one input constraint matches each output.
566  assert(TiedTo < InputMatchedToOutput.size() && "TiedTo value out of range");
567  if (InputMatchedToOutput[TiedTo] != ~0U) {
568  targetDiag(NS->getInputExpr(i)->getBeginLoc(),
569  diag::err_asm_input_duplicate_match)
570  << TiedTo;
571  targetDiag(NS->getInputExpr(InputMatchedToOutput[TiedTo])->getBeginLoc(),
572  diag::note_asm_input_duplicate_first)
573  << TiedTo;
574  return NS;
575  }
576  InputMatchedToOutput[TiedTo] = i;
577 
578  if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent())
579  continue;
580 
581  QualType InTy = InputExpr->getType();
582  QualType OutTy = OutputExpr->getType();
583  if (Context.hasSameType(InTy, OutTy))
584  continue; // All types can be tied to themselves.
585 
586  // Decide if the input and output are in the same domain (integer/ptr or
587  // floating point.
588  enum AsmDomain {
589  AD_Int, AD_FP, AD_Other
590  } InputDomain, OutputDomain;
591 
592  if (InTy->isIntegerType() || InTy->isPointerType())
593  InputDomain = AD_Int;
594  else if (InTy->isRealFloatingType())
595  InputDomain = AD_FP;
596  else
597  InputDomain = AD_Other;
598 
599  if (OutTy->isIntegerType() || OutTy->isPointerType())
600  OutputDomain = AD_Int;
601  else if (OutTy->isRealFloatingType())
602  OutputDomain = AD_FP;
603  else
604  OutputDomain = AD_Other;
605 
606  // They are ok if they are the same size and in the same domain. This
607  // allows tying things like:
608  // void* to int*
609  // void* to int if they are the same size.
610  // double to long double if they are the same size.
611  //
612  uint64_t OutSize = Context.getTypeSize(OutTy);
613  uint64_t InSize = Context.getTypeSize(InTy);
614  if (OutSize == InSize && InputDomain == OutputDomain &&
615  InputDomain != AD_Other)
616  continue;
617 
618  // If the smaller input/output operand is not mentioned in the asm string,
619  // then we can promote the smaller one to a larger input and the asm string
620  // won't notice.
621  bool SmallerValueMentioned = false;
622 
623  // If this is a reference to the input and if the input was the smaller
624  // one, then we have to reject this asm.
625  if (isOperandMentioned(InputOpNo, Pieces)) {
626  // This is a use in the asm string of the smaller operand. Since we
627  // codegen this by promoting to a wider value, the asm will get printed
628  // "wrong".
629  SmallerValueMentioned |= InSize < OutSize;
630  }
631  if (isOperandMentioned(TiedTo, Pieces)) {
632  // If this is a reference to the output, and if the output is the larger
633  // value, then it's ok because we'll promote the input to the larger type.
634  SmallerValueMentioned |= OutSize < InSize;
635  }
636 
637  // If the smaller value wasn't mentioned in the asm string, and if the
638  // output was a register, just extend the shorter one to the size of the
639  // larger one.
640  if (!SmallerValueMentioned && InputDomain != AD_Other &&
641  OutputConstraintInfos[TiedTo].allowsRegister())
642  continue;
643 
644  // Either both of the operands were mentioned or the smaller one was
645  // mentioned. One more special case that we'll allow: if the tied input is
646  // integer, unmentioned, and is a constant, then we'll allow truncating it
647  // down to the size of the destination.
648  if (InputDomain == AD_Int && OutputDomain == AD_Int &&
649  !isOperandMentioned(InputOpNo, Pieces) &&
650  InputExpr->isEvaluatable(Context)) {
651  CastKind castKind =
652  (OutTy->isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast);
653  InputExpr = ImpCastExprToType(InputExpr, OutTy, castKind).get();
654  Exprs[InputOpNo] = InputExpr;
655  NS->setInputExpr(i, InputExpr);
656  continue;
657  }
658 
659  targetDiag(InputExpr->getBeginLoc(), diag::err_asm_tying_incompatible_types)
660  << InTy << OutTy << OutputExpr->getSourceRange()
661  << InputExpr->getSourceRange();
662  return NS;
663  }
664 
665  // Check for conflicts between clobber list and input or output lists
666  SourceLocation ConstraintLoc =
667  getClobberConflictLocation(Exprs, Constraints, Clobbers, NumClobbers,
668  NumLabels,
669  Context.getTargetInfo(), Context);
670  if (ConstraintLoc.isValid())
671  targetDiag(ConstraintLoc, diag::error_inoutput_conflict_with_clobber);
672 
673  // Check for duplicate asm operand name between input, output and label lists.
674  typedef std::pair<StringRef , Expr *> NamedOperand;
675  SmallVector<NamedOperand, 4> NamedOperandList;
676  for (unsigned i = 0, e = NumOutputs + NumInputs + NumLabels; i != e; ++i)
677  if (Names[i])
678  NamedOperandList.emplace_back(
679  std::make_pair(Names[i]->getName(), Exprs[i]));
680  // Sort NamedOperandList.
681  std::stable_sort(NamedOperandList.begin(), NamedOperandList.end(),
682  [](const NamedOperand &LHS, const NamedOperand &RHS) {
683  return LHS.first < RHS.first;
684  });
685  // Find adjacent duplicate operand.
687  std::adjacent_find(begin(NamedOperandList), end(NamedOperandList),
688  [](const NamedOperand &LHS, const NamedOperand &RHS) {
689  return LHS.first == RHS.first;
690  });
691  if (Found != NamedOperandList.end()) {
692  Diag((Found + 1)->second->getBeginLoc(),
693  diag::error_duplicate_asm_operand_name)
694  << (Found + 1)->first;
695  Diag(Found->second->getBeginLoc(), diag::note_duplicate_asm_operand_name)
696  << Found->first;
697  return StmtError();
698  }
699  if (NS->isAsmGoto())
700  setFunctionHasBranchIntoScope();
701  return NS;
702 }
703 
705  llvm::InlineAsmIdentifierInfo &Info) {
706  QualType T = Res->getType();
707  Expr::EvalResult Eval;
708  if (T->isFunctionType() || T->isDependentType())
709  return Info.setLabel(Res);
710  if (Res->isRValue()) {
711  if (isa<clang::EnumType>(T) && Res->EvaluateAsRValue(Eval, Context))
712  return Info.setEnum(Eval.Val.getInt().getSExtValue());
713  return Info.setLabel(Res);
714  }
715  unsigned Size = Context.getTypeSizeInChars(T).getQuantity();
716  unsigned Type = Size;
717  if (const auto *ATy = Context.getAsArrayType(T))
718  Type = Context.getTypeSizeInChars(ATy->getElementType()).getQuantity();
719  bool IsGlobalLV = false;
720  if (Res->EvaluateAsLValue(Eval, Context))
721  IsGlobalLV = Eval.isGlobalLValue();
722  Info.setVar(Res, IsGlobalLV, Size, Type);
723 }
724 
726  SourceLocation TemplateKWLoc,
727  UnqualifiedId &Id,
728  bool IsUnevaluatedContext) {
729 
730  if (IsUnevaluatedContext)
731  PushExpressionEvaluationContext(
732  ExpressionEvaluationContext::UnevaluatedAbstract,
733  ReuseLambdaContextDecl);
734 
735  ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id,
736  /*trailing lparen*/ false,
737  /*is & operand*/ false,
738  /*CorrectionCandidateCallback=*/nullptr,
739  /*IsInlineAsmIdentifier=*/ true);
740 
741  if (IsUnevaluatedContext)
742  PopExpressionEvaluationContext();
743 
744  if (!Result.isUsable()) return Result;
745 
746  Result = CheckPlaceholderExpr(Result.get());
747  if (!Result.isUsable()) return Result;
748 
749  // Referring to parameters is not allowed in naked functions.
750  if (CheckNakedParmReference(Result.get(), *this))
751  return ExprError();
752 
753  QualType T = Result.get()->getType();
754 
755  if (T->isDependentType()) {
756  return Result;
757  }
758 
759  // Any sort of function type is fine.
760  if (T->isFunctionType()) {
761  return Result;
762  }
763 
764  // Otherwise, it needs to be a complete type.
765  if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
766  return ExprError();
767  }
768 
769  return Result;
770 }
771 
772 bool Sema::LookupInlineAsmField(StringRef Base, StringRef Member,
773  unsigned &Offset, SourceLocation AsmLoc) {
774  Offset = 0;
776  Member.split(Members, ".");
777 
778  NamedDecl *FoundDecl = nullptr;
779 
780  // MS InlineAsm uses 'this' as a base
781  if (getLangOpts().CPlusPlus && Base.equals("this")) {
782  if (const Type *PT = getCurrentThisType().getTypePtrOrNull())
783  FoundDecl = PT->getPointeeType()->getAsTagDecl();
784  } else {
785  LookupResult BaseResult(*this, &Context.Idents.get(Base), SourceLocation(),
786  LookupOrdinaryName);
787  if (LookupName(BaseResult, getCurScope()) && BaseResult.isSingleResult())
788  FoundDecl = BaseResult.getFoundDecl();
789  }
790 
791  if (!FoundDecl)
792  return true;
793 
794  for (StringRef NextMember : Members) {
795  const RecordType *RT = nullptr;
796  if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
797  RT = VD->getType()->getAs<RecordType>();
798  else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl)) {
799  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
800  // MS InlineAsm often uses struct pointer aliases as a base
801  QualType QT = TD->getUnderlyingType();
802  if (const auto *PT = QT->getAs<PointerType>())
803  QT = PT->getPointeeType();
804  RT = QT->getAs<RecordType>();
805  } else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
806  RT = TD->getTypeForDecl()->getAs<RecordType>();
807  else if (FieldDecl *TD = dyn_cast<FieldDecl>(FoundDecl))
808  RT = TD->getType()->getAs<RecordType>();
809  if (!RT)
810  return true;
811 
812  if (RequireCompleteType(AsmLoc, QualType(RT, 0),
813  diag::err_asm_incomplete_type))
814  return true;
815 
816  LookupResult FieldResult(*this, &Context.Idents.get(NextMember),
817  SourceLocation(), LookupMemberName);
818 
819  if (!LookupQualifiedName(FieldResult, RT->getDecl()))
820  return true;
821 
822  if (!FieldResult.isSingleResult())
823  return true;
824  FoundDecl = FieldResult.getFoundDecl();
825 
826  // FIXME: Handle IndirectFieldDecl?
827  FieldDecl *FD = dyn_cast<FieldDecl>(FoundDecl);
828  if (!FD)
829  return true;
830 
831  const ASTRecordLayout &RL = Context.getASTRecordLayout(RT->getDecl());
832  unsigned i = FD->getFieldIndex();
833  CharUnits Result = Context.toCharUnitsFromBits(RL.getFieldOffset(i));
834  Offset += (unsigned)Result.getQuantity();
835  }
836 
837  return false;
838 }
839 
842  SourceLocation AsmLoc) {
843 
844  QualType T = E->getType();
845  if (T->isDependentType()) {
846  DeclarationNameInfo NameInfo;
847  NameInfo.setLoc(AsmLoc);
848  NameInfo.setName(&Context.Idents.get(Member));
850  Context, E, T, /*IsArrow=*/false, AsmLoc, NestedNameSpecifierLoc(),
851  SourceLocation(),
852  /*FirstQualifierFoundInScope=*/nullptr, NameInfo, /*TemplateArgs=*/nullptr);
853  }
854 
855  const RecordType *RT = T->getAs<RecordType>();
856  // FIXME: Diagnose this as field access into a scalar type.
857  if (!RT)
858  return ExprResult();
859 
860  LookupResult FieldResult(*this, &Context.Idents.get(Member), AsmLoc,
861  LookupMemberName);
862 
863  if (!LookupQualifiedName(FieldResult, RT->getDecl()))
864  return ExprResult();
865 
866  // Only normal and indirect field results will work.
867  ValueDecl *FD = dyn_cast<FieldDecl>(FieldResult.getFoundDecl());
868  if (!FD)
869  FD = dyn_cast<IndirectFieldDecl>(FieldResult.getFoundDecl());
870  if (!FD)
871  return ExprResult();
872 
873  // Make an Expr to thread through OpDecl.
874  ExprResult Result = BuildMemberReferenceExpr(
875  E, E->getType(), AsmLoc, /*IsArrow=*/false, CXXScopeSpec(),
876  SourceLocation(), nullptr, FieldResult, nullptr, nullptr);
877 
878  return Result;
879 }
880 
882  ArrayRef<Token> AsmToks,
883  StringRef AsmString,
884  unsigned NumOutputs, unsigned NumInputs,
885  ArrayRef<StringRef> Constraints,
886  ArrayRef<StringRef> Clobbers,
887  ArrayRef<Expr*> Exprs,
888  SourceLocation EndLoc) {
889  bool IsSimple = (NumOutputs != 0 || NumInputs != 0);
890  setFunctionHasBranchProtectedScope();
891  MSAsmStmt *NS =
892  new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
893  /*IsVolatile*/ true, AsmToks, NumOutputs, NumInputs,
894  Constraints, Exprs, AsmString,
895  Clobbers, EndLoc);
896  return NS;
897 }
898 
899 LabelDecl *Sema::GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
900  SourceLocation Location,
901  bool AlwaysCreate) {
902  LabelDecl* Label = LookupOrCreateLabel(PP.getIdentifierInfo(ExternalLabelName),
903  Location);
904 
905  if (Label->isMSAsmLabel()) {
906  // If we have previously created this label implicitly, mark it as used.
907  Label->markUsed(Context);
908  } else {
909  // Otherwise, insert it, but only resolve it if we have seen the label itself.
910  std::string InternalName;
911  llvm::raw_string_ostream OS(InternalName);
912  // Create an internal name for the label. The name should not be a valid
913  // mangled name, and should be unique. We use a dot to make the name an
914  // invalid mangled name. We use LLVM's inline asm ${:uid} escape so that a
915  // unique label is generated each time this blob is emitted, even after
916  // inlining or LTO.
917  OS << "__MSASMLABEL_.${:uid}__";
918  for (char C : ExternalLabelName) {
919  OS << C;
920  // We escape '$' in asm strings by replacing it with "$$"
921  if (C == '$')
922  OS << '$';
923  }
924  Label->setMSAsmLabel(OS.str());
925  }
926  if (AlwaysCreate) {
927  // The label might have been created implicitly from a previously encountered
928  // goto statement. So, for both newly created and looked up labels, we mark
929  // them as resolved.
930  Label->setMSAsmLabelResolved();
931  }
932  // Adjust their location for being able to generate accurate diagnostics.
933  Label->setLocation(Location);
934 
935  return Label;
936 }
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:2852
Represents a function declaration or definition.
Definition: Decl.h:1748
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
unsigned getNumInputs() const
Definition: Stmt.h:2764
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2569
A (possibly-)qualified type.
Definition: Type.h:643
void FillInlineAsmIdentifierInfo(Expr *Res, llvm::InlineAsmIdentifierInfo &Info)
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
Stmt - This represents one statement.
Definition: Stmt.h:66
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:505
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:1968
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1019
unsigned getNumOutputs() const
Definition: Stmt.h:2742
bool isAscii() const
Definition: Expr.h:1800
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1362
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:3949
static void emitAndFixInvalidAsmCastLValue(const Expr *LVal, Expr *BadArgument, Sema &S)
Emit a warning about usage of "noop"-like casts for lvalues (GNU extension) and fix the argument with...
Definition: SemaStmtAsm.cpp:69
The base class of the type hierarchy.
Definition: Type.h:1433
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
Definition: TargetInfo.cpp:634
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:693
isModifiableLvalueResult
Definition: Expr.h:278
__m128i_u * p
Definition: emmintrin.h:2134
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:443
Represents a variable declaration or definition.
Definition: Decl.h:812
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:264
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6851
unsigned AnalyzeAsmString(SmallVectorImpl< AsmStringPiece > &Pieces, const ASTContext &C, unsigned &DiagOffs) const
AnalyzeAsmString - Analyze the asm string of the current asm, decomposing it into pieces...
Definition: Stmt.cpp:523
Defines the clang::Expr interface and subclasses for C++ expressions.
long i
Definition: xmmintrin.h:1456
static bool checkExprMemoryConstraintCompat(Sema &S, Expr *E, TargetInfo::ConstraintInfo &Info, bool is_input_expr)
Returns true if given expression is not compatible with inline assembly&#39;s memory constraint; false ot...
One of these records is kept for each identifier that is lexed.
SourceLocation getBegin() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
A C++ nested-name-specifier augmented with source location information.
StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical=false) const
Returns the "normalized" GCC register name.
Definition: TargetInfo.cpp:496
virtual bool validateConstraintModifier(StringRef, char, unsigned, std::string &) const
Definition: TargetInfo.h:951
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:263
Represents a member of a struct/union/class.
Definition: Decl.h:2607
CharSourceRange getRange() const
Definition: Stmt.h:2919
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
bool isAsmGoto() const
Definition: Stmt.h:2997
Expr * getSubExpr()
Definition: Expr.h:3173
static bool isOperandMentioned(unsigned OpNo, ArrayRef< GCCAsmStmt::AsmStringPiece > AsmStrPieces)
isOperandMentioned - Return true if the specified operand # is mentioned anywhere in the decomposed a...
IdentifierTable & Idents
Definition: ASTContext.h:569
LabelDecl * GetOrCreateMSAsmLabel(StringRef ExternalLabelName, SourceLocation Location, bool AlwaysCreate)
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:944
Represents the results of name lookup.
Definition: Lookup.h:46
PtrTy get() const
Definition: Ownership.h:170
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
Definition: Expr.h:446
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:37
APValue Val
Val - This is the value the expression can be folded to.
Definition: Expr.h:582
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:414
child_range children()
Definition: Stmt.cpp:212
StmtResult StmtError()
Definition: Ownership.h:280
Represents a declaration of a type.
Definition: Decl.h:2907
virtual StringRef getConstraintRegister(StringRef Constraint, StringRef Expression) const
Extracts a register from the passed constraint (if it is a single-register constraint) and the asm la...
Definition: TargetInfo.h:818
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:428
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3121
const LangOptions & getLangOpts() const
Definition: Sema.h:1285
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:176
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
Definition: TargetInfo.cpp:451
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2926
NodeId Parent
Definition: ASTDiff.cpp:191
ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool IsUnevaluatedContext)
bool hasAttr() const
Definition: DeclBase.h:542
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:328
StringRef getString() const
Definition: Expr.h:1764
bool isValidClobber(StringRef Name) const
Returns whether the passed in string is a valid clobber in an inline asm statement.
Definition: TargetInfo.cpp:443
CastKind
CastKind - The kind of operation required for a conversion.
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
unsigned getOperandNo() const
Definition: Stmt.h:2914
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:178
static bool CheckNakedParmReference(Expr *E, Sema &S)
unsigned Offset
Definition: Format.cpp:1713
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:38
Exposes information about the current target.
Definition: TargetInfo.h:161
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
This represents one expression.
Definition: Expr.h:108
std::string Label
int Id
Definition: ASTDiff.cpp:190
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
Definition: Stmt.h:2887
Defines the clang::Preprocessor interface.
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1357
Defines the clang::TypeLoc interface and its subclasses.
QualType getType() const
Definition: Expr.h:137
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
Definition: Expr.h:431
ActionResult< CXXBaseSpecifier * > BaseResult
Definition: Ownership.h:266
This represents a Microsoft inline-assembly statement extension.
Definition: Stmt.h:3075
bool isInvalid() const
Definition: Ownership.h:166
void setLocation(SourceLocation L)
Definition: DeclBase.h:430
bool isUsable() const
Definition: Ownership.h:167
RecordDecl * getDecl() const
Definition: Type.h:4448
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:190
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:153
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static StringRef extractRegisterName(const Expr *Expression, const TargetInfo &Target)
ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, SourceLocation AsmLoc)
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
Represents the declaration of a label.
Definition: Decl.h:468
static void removeLValueToRValueCast(Expr *E)
Remove the upper-level LValueToRValue cast from an expression.
Definition: SemaStmtAsm.cpp:30
const std::string & getString() const
Definition: Stmt.h:2912
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
bool validateOutputConstraint(ConstraintInfo &Info) const
Definition: TargetInfo.cpp:537
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:158
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1856
bool isMSAsmLabel() const
Definition: Decl.h:502
bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset, SourceLocation AsmLoc)
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
Definition: Expr.h:258
isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, does not have an incomplet...
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
Definition: Expr.cpp:3862
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:439
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2949
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
EvalResult is a struct with detailed info about an evaluated expression.
Definition: Expr.h:580
static std::string getName(const CallEvent &Call)
StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr *> Exprs, SourceLocation EndLoc)
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2858
void setSubExpr(Expr *E)
Definition: Expr.h:3175
bool isBooleanType() const
Definition: Type.h:6760
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition: Stmt.cpp:419
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand...
Definition: TargetInfo.h:868
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition: APValue.cpp:687
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
const std::string & getConstraintStr() const
Definition: TargetInfo.h:852
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4438
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:6677
T * getAttr() const
Definition: DeclBase.h:538
bool isFunctionType() const
Definition: Type.h:6380
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2296
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition: DeclBase.cpp:412
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2079
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:2062
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
bool refersToGlobalRegisterVar() const
Returns whether this expression refers to a global register variable.
Definition: Expr.cpp:3888
ActionResult< Expr * > ExprResult
Definition: Ownership.h:263
virtual bool validateOutputSize(StringRef, unsigned) const
Definition: TargetInfo.h:941
bool isVoidType() const
Definition: Type.h:6643
static bool CheckAsmLValue(Expr *E, Sema &S)
CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently ignore "noop" casts in p...
Definition: SemaStmtAsm.cpp:88
void setMSAsmLabel(StringRef Name)
Definition: Decl.cpp:4541
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:386
bool isRValue() const
Definition: Expr.h:259
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Definition: Diagnostic.h:129
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:251
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1681
Defines the clang::TargetInfo interface.
ExprResult ExprError()
Definition: Ownership.h:279
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2108
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1141
bool isPointerType() const
Definition: Type.h:6384
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
void setMSAsmLabelResolved()
Definition: Decl.h:506
virtual bool validateInputSize(StringRef, unsigned) const
Definition: TargetInfo.h:946
ASTContext & Context
Definition: Sema.h:374
This represents a decl that may have a name.
Definition: Decl.h:248
APSInt & getInt()
Definition: APValue.h:336
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parenthese and casts which do not change the value (including ptr->int casts of the sam...
Definition: Expr.cpp:2969
static SourceLocation getClobberConflictLocation(MultiExprArg Exprs, StringLiteral **Constraints, StringLiteral **Clobbers, int NumClobbers, unsigned NumLabels, const TargetInfo &Target, ASTContext &Cont)
Attr - This represents one attribute.
Definition: Attr.h:43