clang  8.0.0
SemaStmtAsm.cpp
Go to the documentation of this file.
1 //===--- SemaStmtAsm.cpp - Semantic Analysis for Asm Statements -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements semantic analysis for inline asm statements.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ExprCXX.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  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(); ++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  SourceLocation RParenLoc) {
246  unsigned NumClobbers = clobbers.size();
247  StringLiteral **Constraints =
248  reinterpret_cast<StringLiteral**>(constraints.data());
249  StringLiteral *AsmString = cast<StringLiteral>(asmString);
250  StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.data());
251 
252  SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
253 
254  // The parser verifies that there is a string literal here.
255  assert(AsmString->isAscii());
256 
257  // If we're compiling CUDA file and function attributes indicate that it's not
258  // for this compilation side, skip all the checks.
259  if (!DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl())) {
260  GCCAsmStmt *NS = new (Context) GCCAsmStmt(
261  Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names,
262  Constraints, Exprs.data(), AsmString, NumClobbers, Clobbers, RParenLoc);
263  return NS;
264  }
265 
266  for (unsigned i = 0; i != NumOutputs; i++) {
267  StringLiteral *Literal = Constraints[i];
268  assert(Literal->isAscii());
269 
270  StringRef OutputName;
271  if (Names[i])
272  OutputName = Names[i]->getName();
273 
274  TargetInfo::ConstraintInfo Info(Literal->getString(), OutputName);
275  if (!Context.getTargetInfo().validateOutputConstraint(Info))
276  return StmtError(
277  Diag(Literal->getBeginLoc(), diag::err_asm_invalid_output_constraint)
278  << Info.getConstraintStr());
279 
280  ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
281  if (ER.isInvalid())
282  return StmtError();
283  Exprs[i] = ER.get();
284 
285  // Check that the output exprs are valid lvalues.
286  Expr *OutputExpr = Exprs[i];
287 
288  // Referring to parameters is not allowed in naked functions.
289  if (CheckNakedParmReference(OutputExpr, *this))
290  return StmtError();
291 
292  // Check that the output expression is compatible with memory constraint.
293  if (Info.allowsMemory() &&
294  checkExprMemoryConstraintCompat(*this, OutputExpr, Info, false))
295  return StmtError();
296 
297  OutputConstraintInfos.push_back(Info);
298 
299  // If this is dependent, just continue.
300  if (OutputExpr->isTypeDependent())
301  continue;
302 
304  OutputExpr->isModifiableLvalue(Context, /*Loc=*/nullptr);
305  switch (IsLV) {
306  case Expr::MLV_Valid:
307  // Cool, this is an lvalue.
308  break;
309  case Expr::MLV_ArrayType:
310  // This is OK too.
311  break;
312  case Expr::MLV_LValueCast: {
313  const Expr *LVal = OutputExpr->IgnoreParenNoopCasts(Context);
314  emitAndFixInvalidAsmCastLValue(LVal, OutputExpr, *this);
315  // Accept, even if we emitted an error diagnostic.
316  break;
317  }
320  if (RequireCompleteType(OutputExpr->getBeginLoc(), Exprs[i]->getType(),
321  diag::err_dereference_incomplete_type))
322  return StmtError();
323  LLVM_FALLTHROUGH;
324  default:
325  return StmtError(Diag(OutputExpr->getBeginLoc(),
326  diag::err_asm_invalid_lvalue_in_output)
327  << OutputExpr->getSourceRange());
328  }
329 
330  unsigned Size = Context.getTypeSize(OutputExpr->getType());
331  if (!Context.getTargetInfo().validateOutputSize(Literal->getString(),
332  Size))
333  return StmtError(
334  Diag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_output_size)
335  << Info.getConstraintStr());
336  }
337 
338  SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
339 
340  for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
341  StringLiteral *Literal = Constraints[i];
342  assert(Literal->isAscii());
343 
344  StringRef InputName;
345  if (Names[i])
346  InputName = Names[i]->getName();
347 
348  TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
349  if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
350  Info)) {
351  return StmtError(
352  Diag(Literal->getBeginLoc(), diag::err_asm_invalid_input_constraint)
353  << Info.getConstraintStr());
354  }
355 
356  ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
357  if (ER.isInvalid())
358  return StmtError();
359  Exprs[i] = ER.get();
360 
361  Expr *InputExpr = Exprs[i];
362 
363  // Referring to parameters is not allowed in naked functions.
364  if (CheckNakedParmReference(InputExpr, *this))
365  return StmtError();
366 
367  // Check that the input expression is compatible with memory constraint.
368  if (Info.allowsMemory() &&
369  checkExprMemoryConstraintCompat(*this, InputExpr, Info, true))
370  return StmtError();
371 
372  // Only allow void types for memory constraints.
373  if (Info.allowsMemory() && !Info.allowsRegister()) {
374  if (CheckAsmLValue(InputExpr, *this))
375  return StmtError(Diag(InputExpr->getBeginLoc(),
376  diag::err_asm_invalid_lvalue_in_input)
377  << Info.getConstraintStr()
378  << InputExpr->getSourceRange());
379  } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
380  if (!InputExpr->isValueDependent()) {
381  Expr::EvalResult EVResult;
382  if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
383  return StmtError(
384  Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
385  << Info.getConstraintStr() << InputExpr->getSourceRange());
386 
387  // For compatibility with GCC, we also allow pointers that would be
388  // integral constant expressions if they were cast to int.
389  llvm::APSInt IntResult;
390  if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
391  Context))
392  return StmtError(
393  Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
394  << Info.getConstraintStr() << InputExpr->getSourceRange());
395 
396  if (!Info.isValidAsmImmediate(IntResult))
397  return StmtError(Diag(InputExpr->getBeginLoc(),
398  diag::err_invalid_asm_value_for_constraint)
399  << IntResult.toString(10) << Info.getConstraintStr()
400  << InputExpr->getSourceRange());
401  }
402 
403  } else {
404  ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
405  if (Result.isInvalid())
406  return StmtError();
407 
408  Exprs[i] = Result.get();
409  }
410 
411  if (Info.allowsRegister()) {
412  if (InputExpr->getType()->isVoidType()) {
413  return StmtError(
414  Diag(InputExpr->getBeginLoc(), diag::err_asm_invalid_type_in_input)
415  << InputExpr->getType() << Info.getConstraintStr()
416  << InputExpr->getSourceRange());
417  }
418  }
419 
420  InputConstraintInfos.push_back(Info);
421 
422  const Type *Ty = Exprs[i]->getType().getTypePtr();
423  if (Ty->isDependentType())
424  continue;
425 
426  if (!Ty->isVoidType() || !Info.allowsMemory())
427  if (RequireCompleteType(InputExpr->getBeginLoc(), Exprs[i]->getType(),
428  diag::err_dereference_incomplete_type))
429  return StmtError();
430 
431  unsigned Size = Context.getTypeSize(Ty);
432  if (!Context.getTargetInfo().validateInputSize(Literal->getString(),
433  Size))
434  return StmtError(
435  Diag(InputExpr->getBeginLoc(), diag::err_asm_invalid_input_size)
436  << Info.getConstraintStr());
437  }
438 
439  // Check that the clobbers are valid.
440  for (unsigned i = 0; i != NumClobbers; i++) {
441  StringLiteral *Literal = Clobbers[i];
442  assert(Literal->isAscii());
443 
444  StringRef Clobber = Literal->getString();
445 
446  if (!Context.getTargetInfo().isValidClobber(Clobber))
447  return StmtError(
448  Diag(Literal->getBeginLoc(), diag::err_asm_unknown_register_name)
449  << Clobber);
450  }
451 
452  GCCAsmStmt *NS =
453  new (Context) GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
454  NumInputs, Names, Constraints, Exprs.data(),
455  AsmString, NumClobbers, Clobbers, RParenLoc);
456  // Validate the asm string, ensuring it makes sense given the operands we
457  // have.
459  unsigned DiagOffs;
460  if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) {
461  Diag(getLocationOfStringLiteralByte(AsmString, DiagOffs), DiagID)
462  << AsmString->getSourceRange();
463  return StmtError();
464  }
465 
466  // Validate constraints and modifiers.
467  for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
468  GCCAsmStmt::AsmStringPiece &Piece = Pieces[i];
469  if (!Piece.isOperand()) continue;
470 
471  // Look for the correct constraint index.
472  unsigned ConstraintIdx = Piece.getOperandNo();
473  unsigned NumOperands = NS->getNumOutputs() + NS->getNumInputs();
474 
475  // Look for the (ConstraintIdx - NumOperands + 1)th constraint with
476  // modifier '+'.
477  if (ConstraintIdx >= NumOperands) {
478  unsigned I = 0, E = NS->getNumOutputs();
479 
480  for (unsigned Cnt = ConstraintIdx - NumOperands; I != E; ++I)
481  if (OutputConstraintInfos[I].isReadWrite() && Cnt-- == 0) {
482  ConstraintIdx = I;
483  break;
484  }
485 
486  assert(I != E && "Invalid operand number should have been caught in "
487  " AnalyzeAsmString");
488  }
489 
490  // Now that we have the right indexes go ahead and check.
491  StringLiteral *Literal = Constraints[ConstraintIdx];
492  const Type *Ty = Exprs[ConstraintIdx]->getType().getTypePtr();
493  if (Ty->isDependentType() || Ty->isIncompleteType())
494  continue;
495 
496  unsigned Size = Context.getTypeSize(Ty);
497  std::string SuggestedModifier;
499  Literal->getString(), Piece.getModifier(), Size,
500  SuggestedModifier)) {
501  Diag(Exprs[ConstraintIdx]->getBeginLoc(),
502  diag::warn_asm_mismatched_size_modifier);
503 
504  if (!SuggestedModifier.empty()) {
505  auto B = Diag(Piece.getRange().getBegin(),
506  diag::note_asm_missing_constraint_modifier)
507  << SuggestedModifier;
508  SuggestedModifier = "%" + SuggestedModifier + Piece.getString();
509  B.AddFixItHint(FixItHint::CreateReplacement(Piece.getRange(),
510  SuggestedModifier));
511  }
512  }
513  }
514 
515  // Validate tied input operands for type mismatches.
516  unsigned NumAlternatives = ~0U;
517  for (unsigned i = 0, e = OutputConstraintInfos.size(); i != e; ++i) {
518  TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
519  StringRef ConstraintStr = Info.getConstraintStr();
520  unsigned AltCount = ConstraintStr.count(',') + 1;
521  if (NumAlternatives == ~0U)
522  NumAlternatives = AltCount;
523  else if (NumAlternatives != AltCount)
524  return StmtError(Diag(NS->getOutputExpr(i)->getBeginLoc(),
525  diag::err_asm_unexpected_constraint_alternatives)
526  << NumAlternatives << AltCount);
527  }
528  SmallVector<size_t, 4> InputMatchedToOutput(OutputConstraintInfos.size(),
529  ~0U);
530  for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
531  TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
532  StringRef ConstraintStr = Info.getConstraintStr();
533  unsigned AltCount = ConstraintStr.count(',') + 1;
534  if (NumAlternatives == ~0U)
535  NumAlternatives = AltCount;
536  else if (NumAlternatives != AltCount)
537  return StmtError(Diag(NS->getInputExpr(i)->getBeginLoc(),
538  diag::err_asm_unexpected_constraint_alternatives)
539  << NumAlternatives << AltCount);
540 
541  // If this is a tied constraint, verify that the output and input have
542  // either exactly the same type, or that they are int/ptr operands with the
543  // same size (int/long, int*/long, are ok etc).
544  if (!Info.hasTiedOperand()) continue;
545 
546  unsigned TiedTo = Info.getTiedOperand();
547  unsigned InputOpNo = i+NumOutputs;
548  Expr *OutputExpr = Exprs[TiedTo];
549  Expr *InputExpr = Exprs[InputOpNo];
550 
551  // Make sure no more than one input constraint matches each output.
552  assert(TiedTo < InputMatchedToOutput.size() && "TiedTo value out of range");
553  if (InputMatchedToOutput[TiedTo] != ~0U) {
554  Diag(NS->getInputExpr(i)->getBeginLoc(),
555  diag::err_asm_input_duplicate_match)
556  << TiedTo;
557  Diag(NS->getInputExpr(InputMatchedToOutput[TiedTo])->getBeginLoc(),
558  diag::note_asm_input_duplicate_first)
559  << TiedTo;
560  return StmtError();
561  }
562  InputMatchedToOutput[TiedTo] = i;
563 
564  if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent())
565  continue;
566 
567  QualType InTy = InputExpr->getType();
568  QualType OutTy = OutputExpr->getType();
569  if (Context.hasSameType(InTy, OutTy))
570  continue; // All types can be tied to themselves.
571 
572  // Decide if the input and output are in the same domain (integer/ptr or
573  // floating point.
574  enum AsmDomain {
575  AD_Int, AD_FP, AD_Other
576  } InputDomain, OutputDomain;
577 
578  if (InTy->isIntegerType() || InTy->isPointerType())
579  InputDomain = AD_Int;
580  else if (InTy->isRealFloatingType())
581  InputDomain = AD_FP;
582  else
583  InputDomain = AD_Other;
584 
585  if (OutTy->isIntegerType() || OutTy->isPointerType())
586  OutputDomain = AD_Int;
587  else if (OutTy->isRealFloatingType())
588  OutputDomain = AD_FP;
589  else
590  OutputDomain = AD_Other;
591 
592  // They are ok if they are the same size and in the same domain. This
593  // allows tying things like:
594  // void* to int*
595  // void* to int if they are the same size.
596  // double to long double if they are the same size.
597  //
598  uint64_t OutSize = Context.getTypeSize(OutTy);
599  uint64_t InSize = Context.getTypeSize(InTy);
600  if (OutSize == InSize && InputDomain == OutputDomain &&
601  InputDomain != AD_Other)
602  continue;
603 
604  // If the smaller input/output operand is not mentioned in the asm string,
605  // then we can promote the smaller one to a larger input and the asm string
606  // won't notice.
607  bool SmallerValueMentioned = false;
608 
609  // If this is a reference to the input and if the input was the smaller
610  // one, then we have to reject this asm.
611  if (isOperandMentioned(InputOpNo, Pieces)) {
612  // This is a use in the asm string of the smaller operand. Since we
613  // codegen this by promoting to a wider value, the asm will get printed
614  // "wrong".
615  SmallerValueMentioned |= InSize < OutSize;
616  }
617  if (isOperandMentioned(TiedTo, Pieces)) {
618  // If this is a reference to the output, and if the output is the larger
619  // value, then it's ok because we'll promote the input to the larger type.
620  SmallerValueMentioned |= OutSize < InSize;
621  }
622 
623  // If the smaller value wasn't mentioned in the asm string, and if the
624  // output was a register, just extend the shorter one to the size of the
625  // larger one.
626  if (!SmallerValueMentioned && InputDomain != AD_Other &&
627  OutputConstraintInfos[TiedTo].allowsRegister())
628  continue;
629 
630  // Either both of the operands were mentioned or the smaller one was
631  // mentioned. One more special case that we'll allow: if the tied input is
632  // integer, unmentioned, and is a constant, then we'll allow truncating it
633  // down to the size of the destination.
634  if (InputDomain == AD_Int && OutputDomain == AD_Int &&
635  !isOperandMentioned(InputOpNo, Pieces) &&
636  InputExpr->isEvaluatable(Context)) {
637  CastKind castKind =
638  (OutTy->isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast);
639  InputExpr = ImpCastExprToType(InputExpr, OutTy, castKind).get();
640  Exprs[InputOpNo] = InputExpr;
641  NS->setInputExpr(i, InputExpr);
642  continue;
643  }
644 
645  Diag(InputExpr->getBeginLoc(), diag::err_asm_tying_incompatible_types)
646  << InTy << OutTy << OutputExpr->getSourceRange()
647  << InputExpr->getSourceRange();
648  return StmtError();
649  }
650 
651  // Check for conflicts between clobber list and input or output lists
652  SourceLocation ConstraintLoc =
653  getClobberConflictLocation(Exprs, Constraints, Clobbers, NumClobbers,
654  Context.getTargetInfo(), Context);
655  if (ConstraintLoc.isValid())
656  return Diag(ConstraintLoc, diag::error_inoutput_conflict_with_clobber);
657 
658  return NS;
659 }
660 
662  llvm::InlineAsmIdentifierInfo &Info) {
663  QualType T = Res->getType();
664  Expr::EvalResult Eval;
665  if (T->isFunctionType() || T->isDependentType())
666  return Info.setLabel(Res);
667  if (Res->isRValue()) {
668  if (isa<clang::EnumType>(T) && Res->EvaluateAsRValue(Eval, Context))
669  return Info.setEnum(Eval.Val.getInt().getSExtValue());
670  return Info.setLabel(Res);
671  }
672  unsigned Size = Context.getTypeSizeInChars(T).getQuantity();
673  unsigned Type = Size;
674  if (const auto *ATy = Context.getAsArrayType(T))
675  Type = Context.getTypeSizeInChars(ATy->getElementType()).getQuantity();
676  bool IsGlobalLV = false;
677  if (Res->EvaluateAsLValue(Eval, Context))
678  IsGlobalLV = Eval.isGlobalLValue();
679  Info.setVar(Res, IsGlobalLV, Size, Type);
680 }
681 
683  SourceLocation TemplateKWLoc,
684  UnqualifiedId &Id,
685  bool IsUnevaluatedContext) {
686 
687  if (IsUnevaluatedContext)
688  PushExpressionEvaluationContext(
689  ExpressionEvaluationContext::UnevaluatedAbstract,
690  ReuseLambdaContextDecl);
691 
692  ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id,
693  /*trailing lparen*/ false,
694  /*is & operand*/ false,
695  /*CorrectionCandidateCallback=*/nullptr,
696  /*IsInlineAsmIdentifier=*/ true);
697 
698  if (IsUnevaluatedContext)
699  PopExpressionEvaluationContext();
700 
701  if (!Result.isUsable()) return Result;
702 
703  Result = CheckPlaceholderExpr(Result.get());
704  if (!Result.isUsable()) return Result;
705 
706  // Referring to parameters is not allowed in naked functions.
707  if (CheckNakedParmReference(Result.get(), *this))
708  return ExprError();
709 
710  QualType T = Result.get()->getType();
711 
712  if (T->isDependentType()) {
713  return Result;
714  }
715 
716  // Any sort of function type is fine.
717  if (T->isFunctionType()) {
718  return Result;
719  }
720 
721  // Otherwise, it needs to be a complete type.
722  if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
723  return ExprError();
724  }
725 
726  return Result;
727 }
728 
729 bool Sema::LookupInlineAsmField(StringRef Base, StringRef Member,
730  unsigned &Offset, SourceLocation AsmLoc) {
731  Offset = 0;
733  Member.split(Members, ".");
734 
735  NamedDecl *FoundDecl = nullptr;
736 
737  // MS InlineAsm uses 'this' as a base
738  if (getLangOpts().CPlusPlus && Base.equals("this")) {
739  if (const Type *PT = getCurrentThisType().getTypePtrOrNull())
740  FoundDecl = PT->getPointeeType()->getAsTagDecl();
741  } else {
742  LookupResult BaseResult(*this, &Context.Idents.get(Base), SourceLocation(),
743  LookupOrdinaryName);
744  if (LookupName(BaseResult, getCurScope()) && BaseResult.isSingleResult())
745  FoundDecl = BaseResult.getFoundDecl();
746  }
747 
748  if (!FoundDecl)
749  return true;
750 
751  for (StringRef NextMember : Members) {
752  const RecordType *RT = nullptr;
753  if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
754  RT = VD->getType()->getAs<RecordType>();
755  else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl)) {
756  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
757  // MS InlineAsm often uses struct pointer aliases as a base
758  QualType QT = TD->getUnderlyingType();
759  if (const auto *PT = QT->getAs<PointerType>())
760  QT = PT->getPointeeType();
761  RT = QT->getAs<RecordType>();
762  } else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
763  RT = TD->getTypeForDecl()->getAs<RecordType>();
764  else if (FieldDecl *TD = dyn_cast<FieldDecl>(FoundDecl))
765  RT = TD->getType()->getAs<RecordType>();
766  if (!RT)
767  return true;
768 
769  if (RequireCompleteType(AsmLoc, QualType(RT, 0),
770  diag::err_asm_incomplete_type))
771  return true;
772 
773  LookupResult FieldResult(*this, &Context.Idents.get(NextMember),
774  SourceLocation(), LookupMemberName);
775 
776  if (!LookupQualifiedName(FieldResult, RT->getDecl()))
777  return true;
778 
779  if (!FieldResult.isSingleResult())
780  return true;
781  FoundDecl = FieldResult.getFoundDecl();
782 
783  // FIXME: Handle IndirectFieldDecl?
784  FieldDecl *FD = dyn_cast<FieldDecl>(FoundDecl);
785  if (!FD)
786  return true;
787 
788  const ASTRecordLayout &RL = Context.getASTRecordLayout(RT->getDecl());
789  unsigned i = FD->getFieldIndex();
790  CharUnits Result = Context.toCharUnitsFromBits(RL.getFieldOffset(i));
791  Offset += (unsigned)Result.getQuantity();
792  }
793 
794  return false;
795 }
796 
799  SourceLocation AsmLoc) {
800 
801  QualType T = E->getType();
802  if (T->isDependentType()) {
803  DeclarationNameInfo NameInfo;
804  NameInfo.setLoc(AsmLoc);
805  NameInfo.setName(&Context.Idents.get(Member));
807  Context, E, T, /*IsArrow=*/false, AsmLoc, NestedNameSpecifierLoc(),
808  SourceLocation(),
809  /*FirstQualifierInScope=*/nullptr, NameInfo, /*TemplateArgs=*/nullptr);
810  }
811 
812  const RecordType *RT = T->getAs<RecordType>();
813  // FIXME: Diagnose this as field access into a scalar type.
814  if (!RT)
815  return ExprResult();
816 
817  LookupResult FieldResult(*this, &Context.Idents.get(Member), AsmLoc,
818  LookupMemberName);
819 
820  if (!LookupQualifiedName(FieldResult, RT->getDecl()))
821  return ExprResult();
822 
823  // Only normal and indirect field results will work.
824  ValueDecl *FD = dyn_cast<FieldDecl>(FieldResult.getFoundDecl());
825  if (!FD)
826  FD = dyn_cast<IndirectFieldDecl>(FieldResult.getFoundDecl());
827  if (!FD)
828  return ExprResult();
829 
830  // Make an Expr to thread through OpDecl.
831  ExprResult Result = BuildMemberReferenceExpr(
832  E, E->getType(), AsmLoc, /*IsArrow=*/false, CXXScopeSpec(),
833  SourceLocation(), nullptr, FieldResult, nullptr, nullptr);
834 
835  return Result;
836 }
837 
839  ArrayRef<Token> AsmToks,
840  StringRef AsmString,
841  unsigned NumOutputs, unsigned NumInputs,
842  ArrayRef<StringRef> Constraints,
843  ArrayRef<StringRef> Clobbers,
844  ArrayRef<Expr*> Exprs,
845  SourceLocation EndLoc) {
846  bool IsSimple = (NumOutputs != 0 || NumInputs != 0);
847  setFunctionHasBranchProtectedScope();
848  MSAsmStmt *NS =
849  new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
850  /*IsVolatile*/ true, AsmToks, NumOutputs, NumInputs,
851  Constraints, Exprs, AsmString,
852  Clobbers, EndLoc);
853  return NS;
854 }
855 
856 LabelDecl *Sema::GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
857  SourceLocation Location,
858  bool AlwaysCreate) {
859  LabelDecl* Label = LookupOrCreateLabel(PP.getIdentifierInfo(ExternalLabelName),
860  Location);
861 
862  if (Label->isMSAsmLabel()) {
863  // If we have previously created this label implicitly, mark it as used.
864  Label->markUsed(Context);
865  } else {
866  // Otherwise, insert it, but only resolve it if we have seen the label itself.
867  std::string InternalName;
868  llvm::raw_string_ostream OS(InternalName);
869  // Create an internal name for the label. The name should not be a valid
870  // mangled name, and should be unique. We use a dot to make the name an
871  // invalid mangled name. We use LLVM's inline asm ${:uid} escape so that a
872  // unique label is generated each time this blob is emitted, even after
873  // inlining or LTO.
874  OS << "__MSASMLABEL_.${:uid}__";
875  for (char C : ExternalLabelName) {
876  OS << C;
877  // We escape '$' in asm strings by replacing it with "$$"
878  if (C == '$')
879  OS << '$';
880  }
881  Label->setMSAsmLabel(OS.str());
882  }
883  if (AlwaysCreate) {
884  // The label might have been created implicitly from a previously encountered
885  // goto statement. So, for both newly created and looked up labels, we mark
886  // them as resolved.
887  Label->setMSAsmLabelResolved();
888  }
889  // Adjust their location for being able to generate accurate diagnostics.
890  Label->setLocation(Location);
891 
892  return Label;
893 }
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:2675
Represents a function declaration or definition.
Definition: Decl.h:1738
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:2591
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2537
A (possibly-)qualified type.
Definition: Type.h:638
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
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, SourceLocation RParenLoc)
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:1937
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1020
unsigned getNumOutputs() const
Definition: Stmt.h:2569
bool isAscii() const
Definition: Expr.h:1685
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1308
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:3797
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:1407
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
Definition: TargetInfo.cpp:624
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:690
isModifiableLvalueResult
Definition: Expr.h:269
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:451
Represents a variable declaration or definition.
Definition: Decl.h:813
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
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:515
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...
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Definition: Expr.h:3167
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:155
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:486
virtual bool validateConstraintModifier(StringRef, char, unsigned, std::string &) const
Definition: TargetInfo.h:921
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:288
Represents a member of a struct/union/class.
Definition: Decl.h:2579
CharSourceRange getRange() const
Definition: Stmt.h:2740
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
Expr * getSubExpr()
Definition: Expr.h:3055
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:566
LabelDecl * GetOrCreateMSAsmLabel(StringRef ExternalLabelName, SourceLocation Location, bool AlwaysCreate)
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:934
Represents the results of name lookup.
Definition: Lookup.h:47
PtrTy get() const
Definition: Ownership.h:174
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
Definition: Expr.h:437
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:573
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:405
child_range children()
Definition: Stmt.cpp:237
StmtResult StmtError()
Definition: Ownership.h:284
Represents a declaration of a type.
Definition: Decl.h:2874
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:790
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:436
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:3003
const LangOptions & getLangOpts() const
Definition: Sema.h:1231
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:167
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
Definition: TargetInfo.cpp:441
NodeId Parent
Definition: ASTDiff.cpp:192
ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool IsUnevaluatedContext)
bool hasAttr() const
Definition: DeclBase.h:531
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:278
StringRef getString() const
Definition: Expr.h:1649
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool isValidClobber(StringRef Name) const
Returns whether the passed in string is a valid clobber in an inline asm statement.
Definition: TargetInfo.cpp:433
Expr * IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY
IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the value (including ptr->int ...
Definition: Expr.cpp:2726
CastKind
CastKind - The kind of operation required for a conversion.
unsigned getOperandNo() const
Definition: Stmt.h:2735
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:1631
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:39
Exposes information about the current target.
Definition: TargetInfo.h:54
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:637
This represents one expression.
Definition: Expr.h:106
std::string Label
int Id
Definition: ASTDiff.cpp:191
static SourceLocation getClobberConflictLocation(MultiExprArg Exprs, StringLiteral **Constraints, StringLiteral **Clobbers, int NumClobbers, const TargetInfo &Target, ASTContext &Cont)
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
Definition: Stmt.h:2708
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:1350
Defines the clang::TypeLoc interface and its subclasses.
QualType getType() const
Definition: Expr.h:128
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
Definition: Expr.h:422
ActionResult< CXXBaseSpecifier * > BaseResult
Definition: Ownership.h:270
This represents a Microsoft inline-assembly statement extension.
Definition: Stmt.h:2850
bool isInvalid() const
Definition: Ownership.h:170
void setLocation(SourceLocation L)
Definition: DeclBase.h:419
bool isUsable() const
Definition: Ownership.h:171
RecordDecl * getDecl() const
Definition: Type.h:4380
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:191
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:157
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)
Represents the declaration of a label.
Definition: Decl.h:469
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:2733
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
bool validateOutputConstraint(ConstraintInfo &Info) const
Definition: TargetInfo.cpp:527
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:149
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1741
bool isMSAsmLabel() const
Definition: Decl.h:503
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:249
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:3642
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:447
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2916
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:571
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:2825
void setSubExpr(Expr *E)
Definition: Expr.h:3057
bool isBooleanType() const
Definition: Type.h:6657
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition: Stmt.cpp:427
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand...
Definition: TargetInfo.h:840
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition: APValue.cpp:603
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
const std::string & getConstraintStr() const
Definition: TargetInfo.h:824
bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D)
Definition: SemaInternal.h:54
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4370
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:6578
T * getAttr() const
Definition: DeclBase.h:527
bool isFunctionType() const
Definition: Type.h:6292
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2269
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:2070
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:2031
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:3668
ActionResult< Expr * > ExprResult
Definition: Ownership.h:267
virtual bool validateOutputSize(StringRef, unsigned) const
Definition: TargetInfo.h:911
bool isVoidType() const
Definition: Type.h:6544
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:4385
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:336
bool isRValue() const
Definition: Expr.h:250
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:276
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1566
Defines the clang::TargetInfo interface.
ExprResult ExprError()
Definition: Ownership.h:283
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2079
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:1041
bool isPointerType() const
Definition: Type.h:6296
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
void setMSAsmLabelResolved()
Definition: Decl.h:507
virtual bool validateInputSize(StringRef, unsigned) const
Definition: TargetInfo.h:916
ASTContext & Context
Definition: Sema.h:324
This represents a decl that may have a name.
Definition: Decl.h:249
APSInt & getInt()
Definition: APValue.h:252
Attr - This represents one attribute.
Definition: Attr.h:44