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