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