clang  12.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  // Disallow _ExtInt, since the backends tend to have difficulties with
300  // non-normal sizes.
301  if (OutputExpr->getType()->isExtIntType())
302  return StmtError(
303  Diag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_type)
304  << OutputExpr->getType() << 0 /*Input*/
305  << OutputExpr->getSourceRange());
306 
307  OutputConstraintInfos.push_back(Info);
308 
309  // If this is dependent, just continue.
310  if (OutputExpr->isTypeDependent())
311  continue;
312 
314  OutputExpr->isModifiableLvalue(Context, /*Loc=*/nullptr);
315  switch (IsLV) {
316  case Expr::MLV_Valid:
317  // Cool, this is an lvalue.
318  break;
319  case Expr::MLV_ArrayType:
320  // This is OK too.
321  break;
322  case Expr::MLV_LValueCast: {
323  const Expr *LVal = OutputExpr->IgnoreParenNoopCasts(Context);
324  emitAndFixInvalidAsmCastLValue(LVal, OutputExpr, *this);
325  // Accept, even if we emitted an error diagnostic.
326  break;
327  }
330  if (RequireCompleteType(OutputExpr->getBeginLoc(), Exprs[i]->getType(),
331  diag::err_dereference_incomplete_type))
332  return StmtError();
333  LLVM_FALLTHROUGH;
334  default:
335  return StmtError(Diag(OutputExpr->getBeginLoc(),
336  diag::err_asm_invalid_lvalue_in_output)
337  << OutputExpr->getSourceRange());
338  }
339 
340  unsigned Size = Context.getTypeSize(OutputExpr->getType());
341  if (!Context.getTargetInfo().validateOutputSize(
342  FeatureMap, Literal->getString(), Size)) {
343  targetDiag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_output_size)
344  << Info.getConstraintStr();
345  return new (Context)
346  GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
347  NumInputs, Names, Constraints, Exprs.data(), AsmString,
348  NumClobbers, Clobbers, NumLabels, RParenLoc);
349  }
350  }
351 
352  SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
353 
354  for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
355  StringLiteral *Literal = Constraints[i];
356  assert(Literal->isAscii());
357 
358  StringRef InputName;
359  if (Names[i])
360  InputName = Names[i]->getName();
361 
362  TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
363  if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
364  Info)) {
365  targetDiag(Literal->getBeginLoc(), diag::err_asm_invalid_input_constraint)
366  << Info.getConstraintStr();
367  return new (Context)
368  GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
369  NumInputs, Names, Constraints, Exprs.data(), AsmString,
370  NumClobbers, Clobbers, NumLabels, RParenLoc);
371  }
372 
373  ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
374  if (ER.isInvalid())
375  return StmtError();
376  Exprs[i] = ER.get();
377 
378  Expr *InputExpr = Exprs[i];
379 
380  // Referring to parameters is not allowed in naked functions.
381  if (CheckNakedParmReference(InputExpr, *this))
382  return StmtError();
383 
384  // Check that the input expression is compatible with memory constraint.
385  if (Info.allowsMemory() &&
386  checkExprMemoryConstraintCompat(*this, InputExpr, Info, true))
387  return StmtError();
388 
389  // Only allow void types for memory constraints.
390  if (Info.allowsMemory() && !Info.allowsRegister()) {
391  if (CheckAsmLValue(InputExpr, *this))
392  return StmtError(Diag(InputExpr->getBeginLoc(),
393  diag::err_asm_invalid_lvalue_in_input)
394  << Info.getConstraintStr()
395  << InputExpr->getSourceRange());
396  } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
397  if (!InputExpr->isValueDependent()) {
398  Expr::EvalResult EVResult;
399  if (InputExpr->EvaluateAsRValue(EVResult, Context, true)) {
400  // For compatibility with GCC, we also allow pointers that would be
401  // integral constant expressions if they were cast to int.
402  llvm::APSInt IntResult;
403  if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
404  Context))
405  if (!Info.isValidAsmImmediate(IntResult))
406  return StmtError(Diag(InputExpr->getBeginLoc(),
407  diag::err_invalid_asm_value_for_constraint)
408  << IntResult.toString(10)
409  << Info.getConstraintStr()
410  << InputExpr->getSourceRange());
411  }
412  }
413 
414  } else {
415  ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
416  if (Result.isInvalid())
417  return StmtError();
418 
419  Exprs[i] = Result.get();
420  }
421 
422  if (Info.allowsRegister()) {
423  if (InputExpr->getType()->isVoidType()) {
424  return StmtError(
425  Diag(InputExpr->getBeginLoc(), diag::err_asm_invalid_type_in_input)
426  << InputExpr->getType() << Info.getConstraintStr()
427  << InputExpr->getSourceRange());
428  }
429  }
430 
431  if (InputExpr->getType()->isExtIntType())
432  return StmtError(
433  Diag(InputExpr->getBeginLoc(), diag::err_asm_invalid_type)
434  << InputExpr->getType() << 1 /*Output*/
435  << InputExpr->getSourceRange());
436 
437  InputConstraintInfos.push_back(Info);
438 
439  const Type *Ty = Exprs[i]->getType().getTypePtr();
440  if (Ty->isDependentType())
441  continue;
442 
443  if (!Ty->isVoidType() || !Info.allowsMemory())
444  if (RequireCompleteType(InputExpr->getBeginLoc(), Exprs[i]->getType(),
445  diag::err_dereference_incomplete_type))
446  return StmtError();
447 
448  unsigned Size = Context.getTypeSize(Ty);
449  if (!Context.getTargetInfo().validateInputSize(FeatureMap,
450  Literal->getString(), Size))
451  return StmtResult(
452  targetDiag(InputExpr->getBeginLoc(), diag::err_asm_invalid_input_size)
453  << Info.getConstraintStr());
454  }
455 
456  // Check that the clobbers are valid.
457  for (unsigned i = 0; i != NumClobbers; i++) {
458  StringLiteral *Literal = Clobbers[i];
459  assert(Literal->isAscii());
460 
461  StringRef Clobber = Literal->getString();
462 
463  if (!Context.getTargetInfo().isValidClobber(Clobber)) {
464  targetDiag(Literal->getBeginLoc(), diag::err_asm_unknown_register_name)
465  << Clobber;
466  return new (Context)
467  GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
468  NumInputs, Names, Constraints, Exprs.data(), AsmString,
469  NumClobbers, Clobbers, NumLabels, RParenLoc);
470  }
471  }
472 
473  GCCAsmStmt *NS =
474  new (Context) GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
475  NumInputs, Names, Constraints, Exprs.data(),
476  AsmString, NumClobbers, Clobbers, NumLabels,
477  RParenLoc);
478  // Validate the asm string, ensuring it makes sense given the operands we
479  // have.
481  unsigned DiagOffs;
482  if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) {
483  targetDiag(getLocationOfStringLiteralByte(AsmString, DiagOffs), DiagID)
484  << AsmString->getSourceRange();
485  return NS;
486  }
487 
488  // Validate constraints and modifiers.
489  for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
490  GCCAsmStmt::AsmStringPiece &Piece = Pieces[i];
491  if (!Piece.isOperand()) continue;
492 
493  // Look for the correct constraint index.
494  unsigned ConstraintIdx = Piece.getOperandNo();
495  unsigned NumOperands = NS->getNumOutputs() + NS->getNumInputs();
496  // Labels are the last in the Exprs list.
497  if (NS->isAsmGoto() && ConstraintIdx >= NumOperands)
498  continue;
499  // Look for the (ConstraintIdx - NumOperands + 1)th constraint with
500  // modifier '+'.
501  if (ConstraintIdx >= NumOperands) {
502  unsigned I = 0, E = NS->getNumOutputs();
503 
504  for (unsigned Cnt = ConstraintIdx - NumOperands; I != E; ++I)
505  if (OutputConstraintInfos[I].isReadWrite() && Cnt-- == 0) {
506  ConstraintIdx = I;
507  break;
508  }
509 
510  assert(I != E && "Invalid operand number should have been caught in "
511  " AnalyzeAsmString");
512  }
513 
514  // Now that we have the right indexes go ahead and check.
515  StringLiteral *Literal = Constraints[ConstraintIdx];
516  const Type *Ty = Exprs[ConstraintIdx]->getType().getTypePtr();
517  if (Ty->isDependentType() || Ty->isIncompleteType())
518  continue;
519 
520  unsigned Size = Context.getTypeSize(Ty);
521  std::string SuggestedModifier;
523  Literal->getString(), Piece.getModifier(), Size,
524  SuggestedModifier)) {
525  targetDiag(Exprs[ConstraintIdx]->getBeginLoc(),
526  diag::warn_asm_mismatched_size_modifier);
527 
528  if (!SuggestedModifier.empty()) {
529  auto B = targetDiag(Piece.getRange().getBegin(),
530  diag::note_asm_missing_constraint_modifier)
531  << SuggestedModifier;
532  SuggestedModifier = "%" + SuggestedModifier + Piece.getString();
533  B << FixItHint::CreateReplacement(Piece.getRange(), SuggestedModifier);
534  }
535  }
536  }
537 
538  // Validate tied input operands for type mismatches.
539  unsigned NumAlternatives = ~0U;
540  for (unsigned i = 0, e = OutputConstraintInfos.size(); i != e; ++i) {
541  TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
542  StringRef ConstraintStr = Info.getConstraintStr();
543  unsigned AltCount = ConstraintStr.count(',') + 1;
544  if (NumAlternatives == ~0U) {
545  NumAlternatives = AltCount;
546  } else if (NumAlternatives != AltCount) {
547  targetDiag(NS->getOutputExpr(i)->getBeginLoc(),
548  diag::err_asm_unexpected_constraint_alternatives)
549  << NumAlternatives << AltCount;
550  return NS;
551  }
552  }
553  SmallVector<size_t, 4> InputMatchedToOutput(OutputConstraintInfos.size(),
554  ~0U);
555  for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
556  TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
557  StringRef ConstraintStr = Info.getConstraintStr();
558  unsigned AltCount = ConstraintStr.count(',') + 1;
559  if (NumAlternatives == ~0U) {
560  NumAlternatives = AltCount;
561  } else if (NumAlternatives != AltCount) {
562  targetDiag(NS->getInputExpr(i)->getBeginLoc(),
563  diag::err_asm_unexpected_constraint_alternatives)
564  << NumAlternatives << AltCount;
565  return NS;
566  }
567 
568  // If this is a tied constraint, verify that the output and input have
569  // either exactly the same type, or that they are int/ptr operands with the
570  // same size (int/long, int*/long, are ok etc).
571  if (!Info.hasTiedOperand()) continue;
572 
573  unsigned TiedTo = Info.getTiedOperand();
574  unsigned InputOpNo = i+NumOutputs;
575  Expr *OutputExpr = Exprs[TiedTo];
576  Expr *InputExpr = Exprs[InputOpNo];
577 
578  // Make sure no more than one input constraint matches each output.
579  assert(TiedTo < InputMatchedToOutput.size() && "TiedTo value out of range");
580  if (InputMatchedToOutput[TiedTo] != ~0U) {
581  targetDiag(NS->getInputExpr(i)->getBeginLoc(),
582  diag::err_asm_input_duplicate_match)
583  << TiedTo;
584  targetDiag(NS->getInputExpr(InputMatchedToOutput[TiedTo])->getBeginLoc(),
585  diag::note_asm_input_duplicate_first)
586  << TiedTo;
587  return NS;
588  }
589  InputMatchedToOutput[TiedTo] = i;
590 
591  if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent())
592  continue;
593 
594  QualType InTy = InputExpr->getType();
595  QualType OutTy = OutputExpr->getType();
596  if (Context.hasSameType(InTy, OutTy))
597  continue; // All types can be tied to themselves.
598 
599  // Decide if the input and output are in the same domain (integer/ptr or
600  // floating point.
601  enum AsmDomain {
602  AD_Int, AD_FP, AD_Other
603  } InputDomain, OutputDomain;
604 
605  if (InTy->isIntegerType() || InTy->isPointerType())
606  InputDomain = AD_Int;
607  else if (InTy->isRealFloatingType())
608  InputDomain = AD_FP;
609  else
610  InputDomain = AD_Other;
611 
612  if (OutTy->isIntegerType() || OutTy->isPointerType())
613  OutputDomain = AD_Int;
614  else if (OutTy->isRealFloatingType())
615  OutputDomain = AD_FP;
616  else
617  OutputDomain = AD_Other;
618 
619  // They are ok if they are the same size and in the same domain. This
620  // allows tying things like:
621  // void* to int*
622  // void* to int if they are the same size.
623  // double to long double if they are the same size.
624  //
625  uint64_t OutSize = Context.getTypeSize(OutTy);
626  uint64_t InSize = Context.getTypeSize(InTy);
627  if (OutSize == InSize && InputDomain == OutputDomain &&
628  InputDomain != AD_Other)
629  continue;
630 
631  // If the smaller input/output operand is not mentioned in the asm string,
632  // then we can promote the smaller one to a larger input and the asm string
633  // won't notice.
634  bool SmallerValueMentioned = false;
635 
636  // If this is a reference to the input and if the input was the smaller
637  // one, then we have to reject this asm.
638  if (isOperandMentioned(InputOpNo, Pieces)) {
639  // This is a use in the asm string of the smaller operand. Since we
640  // codegen this by promoting to a wider value, the asm will get printed
641  // "wrong".
642  SmallerValueMentioned |= InSize < OutSize;
643  }
644  if (isOperandMentioned(TiedTo, Pieces)) {
645  // If this is a reference to the output, and if the output is the larger
646  // value, then it's ok because we'll promote the input to the larger type.
647  SmallerValueMentioned |= OutSize < InSize;
648  }
649 
650  // If the smaller value wasn't mentioned in the asm string, and if the
651  // output was a register, just extend the shorter one to the size of the
652  // larger one.
653  if (!SmallerValueMentioned && InputDomain != AD_Other &&
654  OutputConstraintInfos[TiedTo].allowsRegister())
655  continue;
656 
657  // Either both of the operands were mentioned or the smaller one was
658  // mentioned. One more special case that we'll allow: if the tied input is
659  // integer, unmentioned, and is a constant, then we'll allow truncating it
660  // down to the size of the destination.
661  if (InputDomain == AD_Int && OutputDomain == AD_Int &&
662  !isOperandMentioned(InputOpNo, Pieces) &&
663  InputExpr->isEvaluatable(Context)) {
664  CastKind castKind =
665  (OutTy->isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast);
666  InputExpr = ImpCastExprToType(InputExpr, OutTy, castKind).get();
667  Exprs[InputOpNo] = InputExpr;
668  NS->setInputExpr(i, InputExpr);
669  continue;
670  }
671 
672  targetDiag(InputExpr->getBeginLoc(), diag::err_asm_tying_incompatible_types)
673  << InTy << OutTy << OutputExpr->getSourceRange()
674  << InputExpr->getSourceRange();
675  return NS;
676  }
677 
678  // Check for conflicts between clobber list and input or output lists
679  SourceLocation ConstraintLoc =
680  getClobberConflictLocation(Exprs, Constraints, Clobbers, NumClobbers,
681  NumLabels,
682  Context.getTargetInfo(), Context);
683  if (ConstraintLoc.isValid())
684  targetDiag(ConstraintLoc, diag::error_inoutput_conflict_with_clobber);
685 
686  // Check for duplicate asm operand name between input, output and label lists.
687  typedef std::pair<StringRef , Expr *> NamedOperand;
688  SmallVector<NamedOperand, 4> NamedOperandList;
689  for (unsigned i = 0, e = NumOutputs + NumInputs + NumLabels; i != e; ++i)
690  if (Names[i])
691  NamedOperandList.emplace_back(
692  std::make_pair(Names[i]->getName(), Exprs[i]));
693  // Sort NamedOperandList.
694  std::stable_sort(NamedOperandList.begin(), NamedOperandList.end(),
695  [](const NamedOperand &LHS, const NamedOperand &RHS) {
696  return LHS.first < RHS.first;
697  });
698  // Find adjacent duplicate operand.
700  std::adjacent_find(begin(NamedOperandList), end(NamedOperandList),
701  [](const NamedOperand &LHS, const NamedOperand &RHS) {
702  return LHS.first == RHS.first;
703  });
704  if (Found != NamedOperandList.end()) {
705  Diag((Found + 1)->second->getBeginLoc(),
706  diag::error_duplicate_asm_operand_name)
707  << (Found + 1)->first;
708  Diag(Found->second->getBeginLoc(), diag::note_duplicate_asm_operand_name)
709  << Found->first;
710  return StmtError();
711  }
712  if (NS->isAsmGoto())
713  setFunctionHasBranchIntoScope();
714  return NS;
715 }
716 
718  llvm::InlineAsmIdentifierInfo &Info) {
719  QualType T = Res->getType();
720  Expr::EvalResult Eval;
721  if (T->isFunctionType() || T->isDependentType())
722  return Info.setLabel(Res);
723  if (Res->isRValue()) {
724  bool IsEnum = isa<clang::EnumType>(T);
725  if (DeclRefExpr *DRE = dyn_cast<clang::DeclRefExpr>(Res))
726  if (DRE->getDecl()->getKind() == Decl::EnumConstant)
727  IsEnum = true;
728  if (IsEnum && Res->EvaluateAsRValue(Eval, Context))
729  return Info.setEnum(Eval.Val.getInt().getSExtValue());
730 
731  return Info.setLabel(Res);
732  }
733  unsigned Size = Context.getTypeSizeInChars(T).getQuantity();
734  unsigned Type = Size;
735  if (const auto *ATy = Context.getAsArrayType(T))
736  Type = Context.getTypeSizeInChars(ATy->getElementType()).getQuantity();
737  bool IsGlobalLV = false;
738  if (Res->EvaluateAsLValue(Eval, Context))
739  IsGlobalLV = Eval.isGlobalLValue();
740  Info.setVar(Res, IsGlobalLV, Size, Type);
741 }
742 
744  SourceLocation TemplateKWLoc,
745  UnqualifiedId &Id,
746  bool IsUnevaluatedContext) {
747 
748  if (IsUnevaluatedContext)
749  PushExpressionEvaluationContext(
750  ExpressionEvaluationContext::UnevaluatedAbstract,
751  ReuseLambdaContextDecl);
752 
753  ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id,
754  /*trailing lparen*/ false,
755  /*is & operand*/ false,
756  /*CorrectionCandidateCallback=*/nullptr,
757  /*IsInlineAsmIdentifier=*/ true);
758 
759  if (IsUnevaluatedContext)
760  PopExpressionEvaluationContext();
761 
762  if (!Result.isUsable()) return Result;
763 
764  Result = CheckPlaceholderExpr(Result.get());
765  if (!Result.isUsable()) return Result;
766 
767  // Referring to parameters is not allowed in naked functions.
768  if (CheckNakedParmReference(Result.get(), *this))
769  return ExprError();
770 
771  QualType T = Result.get()->getType();
772 
773  if (T->isDependentType()) {
774  return Result;
775  }
776 
777  // Any sort of function type is fine.
778  if (T->isFunctionType()) {
779  return Result;
780  }
781 
782  // Otherwise, it needs to be a complete type.
783  if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
784  return ExprError();
785  }
786 
787  return Result;
788 }
789 
790 bool Sema::LookupInlineAsmField(StringRef Base, StringRef Member,
791  unsigned &Offset, SourceLocation AsmLoc) {
792  Offset = 0;
794  Member.split(Members, ".");
795 
796  NamedDecl *FoundDecl = nullptr;
797 
798  // MS InlineAsm uses 'this' as a base
799  if (getLangOpts().CPlusPlus && Base.equals("this")) {
800  if (const Type *PT = getCurrentThisType().getTypePtrOrNull())
801  FoundDecl = PT->getPointeeType()->getAsTagDecl();
802  } else {
803  LookupResult BaseResult(*this, &Context.Idents.get(Base), SourceLocation(),
804  LookupOrdinaryName);
805  if (LookupName(BaseResult, getCurScope()) && BaseResult.isSingleResult())
806  FoundDecl = BaseResult.getFoundDecl();
807  }
808 
809  if (!FoundDecl)
810  return true;
811 
812  for (StringRef NextMember : Members) {
813  const RecordType *RT = nullptr;
814  if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
815  RT = VD->getType()->getAs<RecordType>();
816  else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl)) {
817  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
818  // MS InlineAsm often uses struct pointer aliases as a base
819  QualType QT = TD->getUnderlyingType();
820  if (const auto *PT = QT->getAs<PointerType>())
821  QT = PT->getPointeeType();
822  RT = QT->getAs<RecordType>();
823  } else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
824  RT = TD->getTypeForDecl()->getAs<RecordType>();
825  else if (FieldDecl *TD = dyn_cast<FieldDecl>(FoundDecl))
826  RT = TD->getType()->getAs<RecordType>();
827  if (!RT)
828  return true;
829 
830  if (RequireCompleteType(AsmLoc, QualType(RT, 0),
831  diag::err_asm_incomplete_type))
832  return true;
833 
834  LookupResult FieldResult(*this, &Context.Idents.get(NextMember),
835  SourceLocation(), LookupMemberName);
836 
837  if (!LookupQualifiedName(FieldResult, RT->getDecl()))
838  return true;
839 
840  if (!FieldResult.isSingleResult())
841  return true;
842  FoundDecl = FieldResult.getFoundDecl();
843 
844  // FIXME: Handle IndirectFieldDecl?
845  FieldDecl *FD = dyn_cast<FieldDecl>(FoundDecl);
846  if (!FD)
847  return true;
848 
849  const ASTRecordLayout &RL = Context.getASTRecordLayout(RT->getDecl());
850  unsigned i = FD->getFieldIndex();
851  CharUnits Result = Context.toCharUnitsFromBits(RL.getFieldOffset(i));
852  Offset += (unsigned)Result.getQuantity();
853  }
854 
855  return false;
856 }
857 
860  SourceLocation AsmLoc) {
861 
862  QualType T = E->getType();
863  if (T->isDependentType()) {
864  DeclarationNameInfo NameInfo;
865  NameInfo.setLoc(AsmLoc);
866  NameInfo.setName(&Context.Idents.get(Member));
868  Context, E, T, /*IsArrow=*/false, AsmLoc, NestedNameSpecifierLoc(),
869  SourceLocation(),
870  /*FirstQualifierFoundInScope=*/nullptr, NameInfo, /*TemplateArgs=*/nullptr);
871  }
872 
873  const RecordType *RT = T->getAs<RecordType>();
874  // FIXME: Diagnose this as field access into a scalar type.
875  if (!RT)
876  return ExprResult();
877 
878  LookupResult FieldResult(*this, &Context.Idents.get(Member), AsmLoc,
879  LookupMemberName);
880 
881  if (!LookupQualifiedName(FieldResult, RT->getDecl()))
882  return ExprResult();
883 
884  // Only normal and indirect field results will work.
885  ValueDecl *FD = dyn_cast<FieldDecl>(FieldResult.getFoundDecl());
886  if (!FD)
887  FD = dyn_cast<IndirectFieldDecl>(FieldResult.getFoundDecl());
888  if (!FD)
889  return ExprResult();
890 
891  // Make an Expr to thread through OpDecl.
892  ExprResult Result = BuildMemberReferenceExpr(
893  E, E->getType(), AsmLoc, /*IsArrow=*/false, CXXScopeSpec(),
894  SourceLocation(), nullptr, FieldResult, nullptr, nullptr);
895 
896  return Result;
897 }
898 
900  ArrayRef<Token> AsmToks,
901  StringRef AsmString,
902  unsigned NumOutputs, unsigned NumInputs,
903  ArrayRef<StringRef> Constraints,
904  ArrayRef<StringRef> Clobbers,
905  ArrayRef<Expr*> Exprs,
906  SourceLocation EndLoc) {
907  bool IsSimple = (NumOutputs != 0 || NumInputs != 0);
908  setFunctionHasBranchProtectedScope();
909 
910  for (uint64_t I = 0; I < NumOutputs + NumInputs; ++I) {
911  if (Exprs[I]->getType()->isExtIntType())
912  return StmtError(
913  Diag(Exprs[I]->getBeginLoc(), diag::err_asm_invalid_type)
914  << Exprs[I]->getType() << (I < NumOutputs)
915  << Exprs[I]->getSourceRange());
916  }
917 
918  MSAsmStmt *NS =
919  new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
920  /*IsVolatile*/ true, AsmToks, NumOutputs, NumInputs,
921  Constraints, Exprs, AsmString,
922  Clobbers, EndLoc);
923  return NS;
924 }
925 
926 LabelDecl *Sema::GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
927  SourceLocation Location,
928  bool AlwaysCreate) {
929  LabelDecl* Label = LookupOrCreateLabel(PP.getIdentifierInfo(ExternalLabelName),
930  Location);
931 
932  if (Label->isMSAsmLabel()) {
933  // If we have previously created this label implicitly, mark it as used.
934  Label->markUsed(Context);
935  } else {
936  // Otherwise, insert it, but only resolve it if we have seen the label itself.
937  std::string InternalName;
938  llvm::raw_string_ostream OS(InternalName);
939  // Create an internal name for the label. The name should not be a valid
940  // mangled name, and should be unique. We use a dot to make the name an
941  // invalid mangled name. We use LLVM's inline asm ${:uid} escape so that a
942  // unique label is generated each time this blob is emitted, even after
943  // inlining or LTO.
944  OS << "__MSASMLABEL_.${:uid}__";
945  for (char C : ExternalLabelName) {
946  OS << C;
947  // We escape '$' in asm strings by replacing it with "$$"
948  if (C == '$')
949  OS << '$';
950  }
951  Label->setMSAsmLabel(OS.str());
952  }
953  if (AlwaysCreate) {
954  // The label might have been created implicitly from a previously encountered
955  // goto statement. So, for both newly created and looked up labels, we mark
956  // them as resolved.
957  Label->setMSAsmLabelResolved();
958  }
959  // Adjust their location for being able to generate accurate diagnostics.
960  Label->setLocation(Location);
961 
962  return Label;
963 }
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:2919
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:2831
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2645
A (possibly-)qualified type.
Definition: Type.h:655
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:68
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:627
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2114
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1029
unsigned getNumOutputs() const
Definition: Stmt.h:2809
bool isAscii() const
Definition: Expr.h:1851
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1517
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:4091
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:1472
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
Definition: TargetInfo.cpp:664
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:647
isModifiableLvalueResult
Definition: Expr.h:293
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:454
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:7153
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:534
CharSourceRange getSourceRange(const SourceRange &Range)
Returns the token CharSourceRange corresponding to Range.
Definition: FixIt.h:32
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:174
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:526
virtual bool validateConstraintModifier(StringRef, char, unsigned, std::string &) const
Definition: TargetInfo.h:1026
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:275
Represents a member of a struct/union/class.
Definition: Decl.h:2746
CharSourceRange getRange() const
Definition: Stmt.h:2986
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
bool isAsmGoto() const
Definition: Stmt.h:3064
Expr * getSubExpr()
Definition: Expr.h:3412
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:584
LabelDecl * GetOrCreateMSAsmLabel(StringRef ExternalLabelName, SourceLocation Location, bool AlwaysCreate)
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:955
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:461
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:608
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:429
child_range children()
Definition: Stmt.cpp:224
StmtResult StmtError()
Definition: Ownership.h:280
Represents a declaration of a type.
Definition: Decl.h:3049
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:891
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:439
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:64
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3373
const LangOptions & getLangOpts() const
Definition: Sema.h:1430
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:186
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
Definition: TargetInfo.cpp:481
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2927
NodeId Parent
Definition: ASTDiff.cpp:192
ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool IsUnevaluatedContext)
bool hasAttr() const
Definition: DeclBase.h:547
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:340
StringRef getString() const
Definition: Expr.h:1815
bool isValidClobber(StringRef Name) const
Returns whether the passed in string is a valid clobber in an inline asm statement.
Definition: TargetInfo.cpp:473
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:2981
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:2020
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:179
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:110
std::string Label
int Id
Definition: ASTDiff.cpp:191
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
Definition: Stmt.h:2954
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:1364
Defines the clang::TypeLoc interface and its subclasses.
QualType getType() const
Definition: Expr.h:142
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
Definition: Expr.h:446
ActionResult< CXXBaseSpecifier * > BaseResult
Definition: Ownership.h:266
This represents a Microsoft inline-assembly statement extension.
Definition: Stmt.h:3142
bool isInvalid() const
Definition: Ownership.h:166
void setLocation(SourceLocation L)
Definition: DeclBase.h:431
bool isUsable() const
Definition: Ownership.h:167
RecordDecl * getDecl() const
Definition: Type.h:4627
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:1020
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:2979
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
bool validateOutputConstraint(ConstraintInfo &Info) const
Definition: TargetInfo.cpp:567
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:169
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1907
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:273
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:3948
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:450
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3091
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:606
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)
bool isExtIntType() const
Definition: Type.h:6868
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:3000
void setSubExpr(Expr *E)
Definition: Expr.h:3414
bool isBooleanType() const
Definition: Type.h:7045
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition: Stmt.cpp:430
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand...
Definition: TargetInfo.h:941
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition: APValue.cpp:629
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
const std::string & getConstraintStr() const
Definition: TargetInfo.h:925
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4617
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:6961
T * getAttr() const
Definition: DeclBase.h:543
bool isFunctionType() const
Definition: Type.h:6646
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2275
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition: DeclBase.cpp:458
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2060
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:2211
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:3974
ActionResult< Expr * > ExprResult
Definition: Ownership.h:263
bool isVoidType() const
Definition: Type.h:6933
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:4698
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:411
bool isRValue() const
Definition: Expr.h:274
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:133
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:1732
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:2185
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:1190
bool isPointerType() const
Definition: Type.h:6650
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:1014
ASTContext & Context
Definition: Sema.h:399
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:2974
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:46