clang 23.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"
15#include "clang/AST/TypeLoc.h"
19#include "clang/Sema/Lookup.h"
21#include "clang/Sema/Scope.h"
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/StringExtras.h"
25#include "llvm/ADT/StringSet.h"
26#include "llvm/MC/MCParser/MCAsmParser.h"
27#include <optional>
28using namespace clang;
29using namespace sema;
30
31/// Remove the upper-level LValueToRValue cast from an expression.
33 Expr *Parent = E;
34 Expr *ExprUnderCast = nullptr;
35 SmallVector<Expr *, 8> ParentsToUpdate;
36
37 while (true) {
38 ParentsToUpdate.push_back(Parent);
39 if (auto *ParenE = dyn_cast<ParenExpr>(Parent)) {
40 Parent = ParenE->getSubExpr();
41 continue;
42 }
43
44 Expr *Child = nullptr;
45 CastExpr *ParentCast = dyn_cast<CastExpr>(Parent);
46 if (ParentCast)
47 Child = ParentCast->getSubExpr();
48 else
49 return;
50
51 if (auto *CastE = dyn_cast<CastExpr>(Child))
52 if (CastE->getCastKind() == CK_LValueToRValue) {
53 ExprUnderCast = CastE->getSubExpr();
54 // LValueToRValue cast inside GCCAsmStmt requires an explicit cast.
55 ParentCast->setSubExpr(ExprUnderCast);
56 break;
57 }
58 Parent = Child;
59 }
60
61 // Update parent expressions to have same ValueType as the underlying.
62 assert(ExprUnderCast &&
63 "Should be reachable only if LValueToRValue cast was found!");
64 auto ValueKind = ExprUnderCast->getValueKind();
65 for (Expr *E : ParentsToUpdate)
66 E->setValueKind(ValueKind);
67}
68
69/// Emit a warning about usage of "noop"-like casts for lvalues (GNU extension)
70/// and fix the argument with removing LValueToRValue cast from the expression.
71static void emitAndFixInvalidAsmCastLValue(const Expr *LVal, Expr *BadArgument,
72 Sema &S) {
73 S.Diag(LVal->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
74 << BadArgument->getSourceRange();
75 removeLValueToRValueCast(BadArgument);
76}
77
78/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently
79/// ignore "noop" casts in places where an lvalue is required by an inline asm.
80/// We emulate this behavior when -fheinous-gnu-extensions is specified, but
81/// provide a strong guidance to not use it.
82///
83/// This method checks to see if the argument is an acceptable l-value and
84/// returns false if it is a case we can handle.
85static bool CheckAsmLValue(Expr *E, Sema &S) {
86 // Type dependent expressions will be checked during instantiation.
87 if (E->isTypeDependent())
88 return false;
89
90 if (E->isLValue())
91 return false; // Cool, this is an lvalue.
92
93 // Okay, this is not an lvalue, but perhaps it is the result of a cast that we
94 // are supposed to allow.
95 const Expr *E2 = E->IgnoreParenNoopCasts(S.Context);
96 if (E != E2 && E2->isLValue()) {
98 // Accept, even if we emitted an error diagnostic.
99 return false;
100 }
101
102 // None of the above, just randomly invalid non-lvalue.
103 return true;
104}
105
106/// isOperandMentioned - Return true if the specified operand # is mentioned
107/// anywhere in the decomposed asm string.
108static bool
109isOperandMentioned(unsigned OpNo,
111 for (unsigned p = 0, e = AsmStrPieces.size(); p != e; ++p) {
112 const GCCAsmStmt::AsmStringPiece &Piece = AsmStrPieces[p];
113 if (!Piece.isOperand())
114 continue;
115
116 // If this is a reference to the input and if the input was the smaller
117 // one, then we have to reject this asm.
118 if (Piece.getOperandNo() == OpNo)
119 return true;
120 }
121 return false;
122}
123
124static bool CheckNakedParmReference(Expr *E, Sema &S) {
125 FunctionDecl *Func = dyn_cast<FunctionDecl>(S.CurContext);
126 if (!Func)
127 return false;
128 if (!Func->hasAttr<NakedAttr>())
129 return false;
130
131 SmallVector<Expr*, 4> WorkList;
132 WorkList.push_back(E);
133 while (WorkList.size()) {
134 Expr *E = WorkList.pop_back_val();
135 if (isa<CXXThisExpr>(E)) {
136 S.Diag(E->getBeginLoc(), diag::err_asm_naked_this_ref);
137 S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
138 return true;
139 }
140 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
141 if (isa<ParmVarDecl>(DRE->getDecl())) {
142 S.Diag(DRE->getBeginLoc(), diag::err_asm_naked_parm_ref);
143 S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
144 return true;
145 }
146 }
147 for (Stmt *Child : E->children()) {
148 if (Expr *E = dyn_cast_or_null<Expr>(Child))
149 WorkList.push_back(E);
150 }
151 }
152 return false;
153}
154
155/// Returns true if given expression is not compatible with inline
156/// assembly's memory constraint; false otherwise.
159 bool is_input_expr) {
160 enum {
161 ExprBitfield = 0,
162 ExprVectorElt,
163 ExprGlobalRegVar,
164 ExprSafeType
165 } EType = ExprSafeType;
166
167 // Bitfields, vector elements and global register variables are not
168 // compatible.
169 if (E->refersToBitField())
170 EType = ExprBitfield;
171 else if (E->refersToVectorElement())
172 EType = ExprVectorElt;
173 else if (E->refersToGlobalRegisterVar())
174 EType = ExprGlobalRegVar;
175
176 if (EType != ExprSafeType) {
177 S.Diag(E->getBeginLoc(), diag::err_asm_non_addr_value_in_memory_constraint)
178 << EType << is_input_expr << Info.getConstraintStr()
179 << E->getSourceRange();
180 return true;
181 }
182
183 return false;
184}
185
186// Extracting the register name from the Expression value,
187// if there is no register name to extract, returns ""
188static StringRef extractRegisterName(const Expr *Expression,
189 const TargetInfo &Target) {
190 Expression = Expression->IgnoreImpCasts();
191 if (const DeclRefExpr *AsmDeclRef = dyn_cast<DeclRefExpr>(Expression)) {
192 // Handle cases where the expression is a variable
193 const VarDecl *Variable = dyn_cast<VarDecl>(AsmDeclRef->getDecl());
194 if (Variable && Variable->getStorageClass() == SC_Register) {
195 if (AsmLabelAttr *Attr = Variable->getAttr<AsmLabelAttr>())
196 if (Target.isValidGCCRegisterName(Attr->getLabel()))
197 return Target.getNormalizedGCCRegisterName(Attr->getLabel(), true);
198 }
199 }
200 return "";
201}
202
203// Checks if there is a conflict between the input and output lists with the
204// clobbers list. If there's a conflict, returns the location of the
205// conflicted clobber, else returns nullptr
206static SourceLocation
208 Expr **Clobbers, int NumClobbers, unsigned NumLabels,
209 const TargetInfo &Target, ASTContext &Cont) {
210 llvm::StringSet<> InOutVars;
211 // Collect all the input and output registers from the extended asm
212 // statement in order to check for conflicts with the clobber list
213 for (unsigned int i = 0; i < Exprs.size() - NumLabels; ++i) {
214 std::string Constraint =
216 StringRef InOutReg = Target.getConstraintRegister(
217 Constraint, extractRegisterName(Exprs[i], Target));
218 if (InOutReg != "")
219 InOutVars.insert(InOutReg);
220 }
221 // Check for each item in the clobber list if it conflicts with the input
222 // or output
223 for (int i = 0; i < NumClobbers; ++i) {
224 std::string Clobber =
226 // We only check registers, therefore we don't check cc and memory
227 // clobbers
228 if (Clobber == "cc" || Clobber == "memory" || Clobber == "unwind")
229 continue;
230 Clobber = Target.getNormalizedGCCRegisterName(Clobber, true);
231 // Go over the output's registers we collected
232 if (InOutVars.count(Clobber))
233 return Clobbers[i]->getBeginLoc();
234 }
235 return SourceLocation();
236}
237
239 if (!Expr)
240 return ExprError();
241
242 if (auto *SL = dyn_cast<StringLiteral>(Expr)) {
243 assert(SL->isOrdinary());
244 if (ForAsmLabel && SL->getString().empty()) {
245 Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
246 << SL->getSourceRange();
247 }
248 return SL;
249 }
251 return ExprError();
252 if (Expr->getDependence() != ExprDependence::None)
253 return Expr;
254 APValue V;
256 /*ErrorOnInvalid=*/true))
257 return ExprError();
258
259 if (ForAsmLabel && V.getArrayInitializedElts() == 0) {
260 Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string);
261 }
262
265 Res->SetResult(V, getASTContext());
266 return Res;
267}
268
270 bool IsVolatile, unsigned NumOutputs,
271 unsigned NumInputs, IdentifierInfo **Names,
272 MultiExprArg constraints, MultiExprArg Exprs,
273 Expr *asmString, MultiExprArg clobbers,
274 unsigned NumLabels,
275 SourceLocation RParenLoc) {
276 unsigned NumClobbers = clobbers.size();
277
278 SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
279
280 FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext());
281 llvm::StringMap<bool> FeatureMap;
282 Context.getFunctionFeatureMap(FeatureMap, FD);
283
284 auto CreateGCCAsmStmt = [&] {
285 return new (Context)
286 GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs,
287 Names, constraints.data(), Exprs.data(), asmString,
288 NumClobbers, clobbers.data(), NumLabels, RParenLoc);
289 };
290
291 if (asmString->getDependence() != ExprDependence::None ||
292 llvm::any_of(
293 constraints,
294 [](Expr *E) { return E->getDependence() != ExprDependence::None; }) ||
295 llvm::any_of(clobbers, [](Expr *E) {
296 return E->getDependence() != ExprDependence::None;
297 }))
298 return CreateGCCAsmStmt();
299
300 for (unsigned i = 0; i != NumOutputs; i++) {
301 Expr *Constraint = constraints[i];
302 StringRef OutputName;
303 if (Names[i])
304 OutputName = Names[i]->getName();
305
306 std::string ConstraintStr =
308
309 if (ConstraintStr.find('\0') != std::string::npos) {
310 Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
311 << /*output*/ 0;
312 return CreateGCCAsmStmt();
313 }
314
315 TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
316 if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
317 !(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
318 targetDiag(Constraint->getBeginLoc(),
319 diag::err_asm_invalid_output_constraint)
320 << Info.getConstraintStr();
321 return CreateGCCAsmStmt();
322 }
323
324 ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
325 if (ER.isInvalid())
326 return StmtError();
327 Exprs[i] = ER.get();
328
329 // Check that the output exprs are valid lvalues.
330 Expr *OutputExpr = Exprs[i];
331
332 // Referring to parameters is not allowed in naked functions.
333 if (CheckNakedParmReference(OutputExpr, *this))
334 return StmtError();
335
336 // Check that the output expression is compatible with memory constraint.
337 if (Info.allowsMemory() &&
338 checkExprMemoryConstraintCompat(*this, OutputExpr, Info, false))
339 return StmtError();
340
341 // Disallow bit-precise integer types, since the backends tend to have
342 // difficulties with abnormal sizes.
343 if (OutputExpr->getType()->isBitIntType())
344 return StmtError(
345 Diag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_type)
346 << OutputExpr->getType() << 0 /*Input*/
347 << OutputExpr->getSourceRange());
348
349 OutputConstraintInfos.push_back(Info);
350
351 // If this is dependent, just continue.
352 if (OutputExpr->isTypeDependent())
353 continue;
354
356 OutputExpr->isModifiableLvalue(Context, /*Loc=*/nullptr);
357 switch (IsLV) {
358 case Expr::MLV_Valid:
359 // Cool, this is an lvalue.
360 break;
362 // This is OK too.
363 break;
365 const Expr *LVal = OutputExpr->IgnoreParenNoopCasts(Context);
366 emitAndFixInvalidAsmCastLValue(LVal, OutputExpr, *this);
367 // Accept, even if we emitted an error diagnostic.
368 break;
369 }
372 if (RequireCompleteType(OutputExpr->getBeginLoc(), Exprs[i]->getType(),
373 diag::err_dereference_incomplete_type))
374 return StmtError();
375 [[fallthrough]];
376 default:
377 return StmtError(Diag(OutputExpr->getBeginLoc(),
378 diag::err_asm_invalid_lvalue_in_output)
379 << OutputExpr->getSourceRange());
380 }
381
382 unsigned Size = Context.getTypeSize(OutputExpr->getType());
383 if (!Context.getTargetInfo().validateOutputSize(
384 FeatureMap,
386 Size)) {
387 targetDiag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_output_size)
388 << Info.getConstraintStr();
389 return CreateGCCAsmStmt();
390 }
391 }
392
394
395 for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
396 Expr *Constraint = constraints[i];
397
398 StringRef InputName;
399 if (Names[i])
400 InputName = Names[i]->getName();
401
402 std::string ConstraintStr =
404
405 if (ConstraintStr.find('\0') != std::string::npos) {
406 Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
407 << /*input*/ 1;
408 return CreateGCCAsmStmt();
409 }
410
411 TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
412 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
413 Info)) {
414 targetDiag(Constraint->getBeginLoc(),
415 diag::err_asm_invalid_input_constraint)
416 << Info.getConstraintStr();
417 return CreateGCCAsmStmt();
418 }
419
420 ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
421 if (ER.isInvalid())
422 return StmtError();
423 Exprs[i] = ER.get();
424
425 Expr *InputExpr = Exprs[i];
426
427 if (InputExpr->getType()->isMemberPointerType())
428 return StmtError(Diag(InputExpr->getBeginLoc(),
429 diag::err_asm_pmf_through_constraint_not_permitted)
430 << InputExpr->getSourceRange());
431
432 // Referring to parameters is not allowed in naked functions.
433 if (CheckNakedParmReference(InputExpr, *this))
434 return StmtError();
435
436 // Check that the input expression is compatible with memory constraint.
437 if (Info.allowsMemory() &&
438 checkExprMemoryConstraintCompat(*this, InputExpr, Info, true))
439 return StmtError();
440
441 // Only allow void types for memory constraints.
442 if (Info.allowsMemory() && !Info.allowsRegister()) {
443 if (CheckAsmLValue(InputExpr, *this))
444 return StmtError(Diag(InputExpr->getBeginLoc(),
445 diag::err_asm_invalid_lvalue_in_input)
446 << Info.getConstraintStr()
447 << InputExpr->getSourceRange());
448 } else {
450 if (Result.isInvalid())
451 return StmtError();
452
453 InputExpr = Exprs[i] = Result.get();
454
455 if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
456 if (!InputExpr->isValueDependent()) {
457 Expr::EvalResult EVResult;
458 if (InputExpr->EvaluateAsRValue(EVResult, Context, true)) {
459 // For compatibility with GCC, we also allow pointers that would be
460 // integral constant expressions if they were cast to int.
461 llvm::APSInt IntResult;
462 if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
463 Context))
464 if (!Info.isValidAsmImmediate(IntResult))
465 return StmtError(
466 Diag(InputExpr->getBeginLoc(),
467 diag::err_invalid_asm_value_for_constraint)
468 << toString(IntResult, 10) << Info.getConstraintStr()
469 << InputExpr->getSourceRange());
470 }
471 }
472 }
473 }
474
475 if (Info.allowsRegister()) {
476 if (InputExpr->getType()->isVoidType()) {
477 return StmtError(
478 Diag(InputExpr->getBeginLoc(), diag::err_asm_invalid_type_in_input)
479 << InputExpr->getType() << Info.getConstraintStr()
480 << InputExpr->getSourceRange());
481 }
482 }
483
484 if (InputExpr->getType()->isBitIntType())
485 return StmtError(
486 Diag(InputExpr->getBeginLoc(), diag::err_asm_invalid_type)
487 << InputExpr->getType() << 1 /*Output*/
488 << InputExpr->getSourceRange());
489
490 InputConstraintInfos.push_back(Info);
491
492 const Type *Ty = Exprs[i]->getType().getTypePtr();
493 if (Ty->isDependentType())
494 continue;
495
496 if (!Ty->isVoidType() || !Info.allowsMemory())
497 if (RequireCompleteType(InputExpr->getBeginLoc(), Exprs[i]->getType(),
498 diag::err_dereference_incomplete_type))
499 return StmtError();
500
501 unsigned Size = Context.getTypeSize(Ty);
502 if (!Context.getTargetInfo().validateInputSize(FeatureMap, ConstraintStr,
503 Size))
504 return targetDiag(InputExpr->getBeginLoc(),
505 diag::err_asm_invalid_input_size)
506 << Info.getConstraintStr();
507 }
508
509 std::optional<SourceLocation> UnwindClobberLoc;
510
511 // Check that the clobbers are valid.
512 for (unsigned i = 0; i != NumClobbers; i++) {
513 Expr *ClobberExpr = clobbers[i];
514
515 std::string Clobber =
517
518 if (Clobber.find('\0') != std::string::npos) {
519 Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
520 << /*clobber*/ 2;
521 return CreateGCCAsmStmt();
522 }
523
524 if (!Context.getTargetInfo().isValidClobber(Clobber)) {
525 targetDiag(ClobberExpr->getBeginLoc(),
526 diag::err_asm_unknown_register_name)
527 << Clobber;
528 return new (Context) GCCAsmStmt(
529 Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names,
530 constraints.data(), Exprs.data(), asmString, NumClobbers,
531 clobbers.data(), NumLabels, RParenLoc);
532 }
533
534 if (Clobber == "unwind") {
535 UnwindClobberLoc = ClobberExpr->getBeginLoc();
536 }
537 }
538
539 // Using unwind clobber and asm-goto together is not supported right now.
540 if (UnwindClobberLoc && NumLabels > 0) {
541 targetDiag(*UnwindClobberLoc, diag::err_asm_unwind_and_goto);
542 return CreateGCCAsmStmt();
543 }
544
545 GCCAsmStmt *NS = CreateGCCAsmStmt();
546 // Validate the asm string, ensuring it makes sense given the operands we
547 // have.
548
549 auto GetLocation = [this](const Expr *Str, unsigned Offset) {
550 if (auto *SL = dyn_cast<StringLiteral>(Str))
551 return getLocationOfStringLiteralByte(SL, Offset);
552 return Str->getBeginLoc();
553 };
554
556 unsigned DiagOffs;
557 if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) {
558 targetDiag(GetLocation(asmString, DiagOffs), DiagID)
559 << asmString->getSourceRange();
560 return NS;
561 }
562
563 // Validate constraints and modifiers.
564 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
565 GCCAsmStmt::AsmStringPiece &Piece = Pieces[i];
566 if (!Piece.isOperand()) continue;
567
568 // Look for the correct constraint index.
569 unsigned ConstraintIdx = Piece.getOperandNo();
570 unsigned NumOperands = NS->getNumOutputs() + NS->getNumInputs();
571 // Labels are the last in the Exprs list.
572 if (NS->isAsmGoto() && ConstraintIdx >= NumOperands)
573 continue;
574 // Look for the (ConstraintIdx - NumOperands + 1)th constraint with
575 // modifier '+'.
576 if (ConstraintIdx >= NumOperands) {
577 unsigned I = 0, E = NS->getNumOutputs();
578
579 for (unsigned Cnt = ConstraintIdx - NumOperands; I != E; ++I)
580 if (OutputConstraintInfos[I].isReadWrite() && Cnt-- == 0) {
581 ConstraintIdx = I;
582 break;
583 }
584
585 assert(I != E && "Invalid operand number should have been caught in "
586 " AnalyzeAsmString");
587 }
588
589 // Now that we have the right indexes go ahead and check.
590 Expr *Constraint = constraints[ConstraintIdx];
591 const Type *Ty = Exprs[ConstraintIdx]->getType().getTypePtr();
592 if (Ty->isDependentType() || Ty->isIncompleteType())
593 continue;
594
595 unsigned Size = Context.getTypeSize(Ty);
596 std::string SuggestedModifier;
597 if (!Context.getTargetInfo().validateConstraintModifier(
599 Piece.getModifier(), Size, SuggestedModifier)) {
600 targetDiag(Exprs[ConstraintIdx]->getBeginLoc(),
601 diag::warn_asm_mismatched_size_modifier);
602
603 if (!SuggestedModifier.empty()) {
604 auto B = targetDiag(Piece.getRange().getBegin(),
605 diag::note_asm_missing_constraint_modifier)
606 << SuggestedModifier;
607 if (isa<StringLiteral>(Constraint)) {
608 SuggestedModifier = "%" + SuggestedModifier + Piece.getString();
610 SuggestedModifier);
611 }
612 }
613 }
614 }
615
616 // Validate tied input operands for type mismatches.
617 unsigned NumAlternatives = ~0U;
618 for (unsigned i = 0, e = OutputConstraintInfos.size(); i != e; ++i) {
619 TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
620 StringRef ConstraintStr = Info.getConstraintStr();
621 unsigned AltCount = ConstraintStr.count(',') + 1;
622 if (NumAlternatives == ~0U) {
623 NumAlternatives = AltCount;
624 } else if (NumAlternatives != AltCount) {
625 targetDiag(NS->getOutputExpr(i)->getBeginLoc(),
626 diag::err_asm_unexpected_constraint_alternatives)
627 << NumAlternatives << AltCount;
628 return NS;
629 }
630 }
631 SmallVector<size_t, 4> InputMatchedToOutput(OutputConstraintInfos.size(),
632 ~0U);
633 for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
634 TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
635 StringRef ConstraintStr = Info.getConstraintStr();
636 unsigned AltCount = ConstraintStr.count(',') + 1;
637 if (NumAlternatives == ~0U) {
638 NumAlternatives = AltCount;
639 } else if (NumAlternatives != AltCount) {
640 targetDiag(NS->getInputExpr(i)->getBeginLoc(),
641 diag::err_asm_unexpected_constraint_alternatives)
642 << NumAlternatives << AltCount;
643 return NS;
644 }
645
646 // If this is a tied constraint, verify that the output and input have
647 // either exactly the same type, or that they are int/ptr operands with the
648 // same size (int/long, int*/long, are ok etc).
649 if (!Info.hasTiedOperand()) continue;
650
651 unsigned TiedTo = Info.getTiedOperand();
652 unsigned InputOpNo = i+NumOutputs;
653 Expr *OutputExpr = Exprs[TiedTo];
654 Expr *InputExpr = Exprs[InputOpNo];
655
656 // Make sure no more than one input constraint matches each output.
657 assert(TiedTo < InputMatchedToOutput.size() && "TiedTo value out of range");
658 if (InputMatchedToOutput[TiedTo] != ~0U) {
659 targetDiag(NS->getInputExpr(i)->getBeginLoc(),
660 diag::err_asm_input_duplicate_match)
661 << TiedTo;
662 targetDiag(NS->getInputExpr(InputMatchedToOutput[TiedTo])->getBeginLoc(),
663 diag::note_asm_input_duplicate_first)
664 << TiedTo;
665 return NS;
666 }
667 InputMatchedToOutput[TiedTo] = i;
668
669 if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent())
670 continue;
671
672 QualType InTy = InputExpr->getType();
673 QualType OutTy = OutputExpr->getType();
674 if (Context.hasSameType(InTy, OutTy))
675 continue; // All types can be tied to themselves.
676
677 // Decide if the input and output are in the same domain (integer/ptr or
678 // floating point.
679 enum AsmDomain {
680 AD_Int, AD_FP, AD_Other
681 } InputDomain, OutputDomain;
682
683 if (InTy->isIntegerType() || InTy->isPointerType())
684 InputDomain = AD_Int;
685 else if (InTy->isRealFloatingType())
686 InputDomain = AD_FP;
687 else
688 InputDomain = AD_Other;
689
690 if (OutTy->isIntegerType() || OutTy->isPointerType())
691 OutputDomain = AD_Int;
692 else if (OutTy->isRealFloatingType())
693 OutputDomain = AD_FP;
694 else
695 OutputDomain = AD_Other;
696
697 // They are ok if they are the same size and in the same domain. This
698 // allows tying things like:
699 // void* to int*
700 // void* to int if they are the same size.
701 // double to long double if they are the same size.
702 //
703 uint64_t OutSize = Context.getTypeSize(OutTy);
704 uint64_t InSize = Context.getTypeSize(InTy);
705 if (OutSize == InSize && InputDomain == OutputDomain &&
706 InputDomain != AD_Other)
707 continue;
708
709 // If the smaller input/output operand is not mentioned in the asm string,
710 // then we can promote the smaller one to a larger input and the asm string
711 // won't notice.
712 bool SmallerValueMentioned = false;
713
714 // If this is a reference to the input and if the input was the smaller
715 // one, then we have to reject this asm.
716 if (isOperandMentioned(InputOpNo, Pieces)) {
717 // This is a use in the asm string of the smaller operand. Since we
718 // codegen this by promoting to a wider value, the asm will get printed
719 // "wrong".
720 SmallerValueMentioned |= InSize < OutSize;
721 }
722 if (isOperandMentioned(TiedTo, Pieces)) {
723 // If this is a reference to the output, and if the output is the larger
724 // value, then it's ok because we'll promote the input to the larger type.
725 SmallerValueMentioned |= OutSize < InSize;
726 }
727
728 // If the input is an integer register while the output is floating point,
729 // or vice-versa, there is no way they can work together.
730 bool FPTiedToInt = (InputDomain == AD_FP) ^ (OutputDomain == AD_FP);
731
732 // If the smaller value wasn't mentioned in the asm string, and if the
733 // output was a register, just extend the shorter one to the size of the
734 // larger one.
735 if (!SmallerValueMentioned && !FPTiedToInt && InputDomain != AD_Other &&
736 OutputConstraintInfos[TiedTo].allowsRegister()) {
737
738 // FIXME: GCC supports some non-scalar register outputs. Currently
739 // codegen crashes when the size cannot be represented by an integer type
740 // that fits in a general-purpose register.
741 bool FitsInGeneralPurposeRegister =
742 OutSize <= Context.getTargetInfo().getRegisterWidth() &&
743 !Context.getIntTypeForBitwidth(OutSize, /*Signed*/ false).isNull();
744 if (OutputDomain == AD_Other && !FitsInGeneralPurposeRegister) {
745 targetDiag(OutputExpr->getExprLoc(), diag::err_store_value_to_reg);
746 return NS;
747 }
748
749 continue;
750 }
751
752 // Either both of the operands were mentioned or the smaller one was
753 // mentioned. One more special case that we'll allow: if the tied input is
754 // integer, unmentioned, and is a constant, then we'll allow truncating it
755 // down to the size of the destination.
756 if (InputDomain == AD_Int && OutputDomain == AD_Int &&
757 !isOperandMentioned(InputOpNo, Pieces) &&
758 InputExpr->isEvaluatable(Context)) {
759 CastKind castKind =
760 (OutTy->isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast);
761 InputExpr = ImpCastExprToType(InputExpr, OutTy, castKind).get();
762 Exprs[InputOpNo] = InputExpr;
763 NS->setInputExpr(i, InputExpr);
764 continue;
765 }
766
767 targetDiag(InputExpr->getBeginLoc(), diag::err_asm_tying_incompatible_types)
768 << InTy << OutTy << OutputExpr->getSourceRange()
769 << InputExpr->getSourceRange();
770 return NS;
771 }
772
773 // Check for conflicts between clobber list and input or output lists
775 Exprs, constraints.data(), clobbers.data(), NumClobbers, NumLabels,
776 Context.getTargetInfo(), Context);
777 if (ConstraintLoc.isValid())
778 targetDiag(ConstraintLoc, diag::error_inoutput_conflict_with_clobber);
779
780 // Check for duplicate asm operand name between input, output and label lists.
781 typedef std::pair<StringRef , Expr *> NamedOperand;
782 SmallVector<NamedOperand, 4> NamedOperandList;
783 for (unsigned i = 0, e = NumOutputs + NumInputs + NumLabels; i != e; ++i)
784 if (Names[i])
785 NamedOperandList.emplace_back(
786 std::make_pair(Names[i]->getName(), Exprs[i]));
787 // Sort NamedOperandList.
788 llvm::stable_sort(NamedOperandList, llvm::less_first());
789 // Find adjacent duplicate operand.
791 std::adjacent_find(begin(NamedOperandList), end(NamedOperandList),
792 [](const NamedOperand &LHS, const NamedOperand &RHS) {
793 return LHS.first == RHS.first;
794 });
795 if (Found != NamedOperandList.end()) {
796 Diag((Found + 1)->second->getBeginLoc(),
797 diag::error_duplicate_asm_operand_name)
798 << (Found + 1)->first;
799 Diag(Found->second->getBeginLoc(), diag::note_duplicate_asm_operand_name)
800 << Found->first;
801 return StmtError();
802 }
803 if (NS->isAsmGoto())
805
808 return NS;
809}
810
812 llvm::InlineAsmIdentifierInfo &Info) {
813 QualType T = Res->getType();
814 Expr::EvalResult Eval;
815 if (T->isFunctionType() || T->isDependentType())
816 return Info.setLabel(Res);
817 if (Res->isPRValue()) {
818 bool IsEnum = isa<clang::EnumType>(T);
819 if (DeclRefExpr *DRE = dyn_cast<clang::DeclRefExpr>(Res))
820 if (DRE->getDecl()->getKind() == Decl::EnumConstant)
821 IsEnum = true;
822 if (IsEnum && Res->EvaluateAsRValue(Eval, Context))
823 return Info.setEnum(Eval.Val.getInt().getSExtValue());
824
825 return Info.setLabel(Res);
826 }
827 unsigned Size = Context.getTypeSizeInChars(T).getQuantity();
828 unsigned Type = Size;
829 if (const auto *ATy = Context.getAsArrayType(T))
830 Type = Context.getTypeSizeInChars(ATy->getElementType()).getQuantity();
831 bool IsGlobalLV = false;
832 if (Res->EvaluateAsLValue(Eval, Context))
833 IsGlobalLV = Eval.isGlobalLValue();
834 Info.setVar(Res, IsGlobalLV, Size, Type);
835}
836
838 SourceLocation TemplateKWLoc,
839 UnqualifiedId &Id,
840 bool IsUnevaluatedContext) {
841
842 if (IsUnevaluatedContext)
846
847 ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id,
848 /*trailing lparen*/ false,
849 /*is & operand*/ false,
850 /*CorrectionCandidateCallback=*/nullptr,
851 /*IsInlineAsmIdentifier=*/ true);
852
853 if (IsUnevaluatedContext)
855
856 if (!Result.isUsable()) return Result;
857
859 if (!Result.isUsable()) return Result;
860
861 // Referring to parameters is not allowed in naked functions.
862 if (CheckNakedParmReference(Result.get(), *this))
863 return ExprError();
864
865 QualType T = Result.get()->getType();
866
867 if (T->isDependentType()) {
868 return Result;
869 }
870
871 // Any sort of function type is fine.
872 if (T->isFunctionType()) {
873 return Result;
874 }
875
876 // Otherwise, it needs to be a complete type.
877 if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
878 return ExprError();
879 }
880
881 return Result;
882}
883
884bool Sema::LookupInlineAsmField(StringRef Base, StringRef Member,
885 unsigned &Offset, SourceLocation AsmLoc) {
886 Offset = 0;
888 Member.split(Members, ".");
889
890 NamedDecl *FoundDecl = nullptr;
891
892 // MS InlineAsm uses 'this' as a base
893 if (getLangOpts().CPlusPlus && Base == "this") {
894 if (const Type *PT = getCurrentThisType().getTypePtrOrNull())
895 FoundDecl = PT->getPointeeType()->getAsTagDecl();
896 } else {
897 LookupResult BaseResult(*this, &Context.Idents.get(Base), SourceLocation(),
899 if (LookupName(BaseResult, getCurScope()) && BaseResult.isSingleResult())
900 FoundDecl = BaseResult.getFoundDecl();
901 }
902
903 if (!FoundDecl)
904 return true;
905
906 for (StringRef NextMember : Members) {
907 const RecordType *RT = nullptr;
908 if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
909 RT = VD->getType()->getAsCanonical<RecordType>();
910 else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl)) {
911 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
912 // MS InlineAsm often uses struct pointer aliases as a base
913 QualType QT = TD->getUnderlyingType();
914 if (const auto *PT = QT->getAs<PointerType>())
915 QT = PT->getPointeeType();
916 RT = QT->getAsCanonical<RecordType>();
917 } else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
918 RT = QualType(Context.getCanonicalTypeDeclType(TD))
919 ->getAsCanonical<RecordType>();
920 else if (FieldDecl *TD = dyn_cast<FieldDecl>(FoundDecl))
921 RT = TD->getType()->getAsCanonical<RecordType>();
922 if (!RT)
923 return true;
924
925 if (RequireCompleteType(AsmLoc, QualType(RT, 0),
926 diag::err_asm_incomplete_type))
927 return true;
928
929 LookupResult FieldResult(*this, &Context.Idents.get(NextMember),
931
932 RecordDecl *RD = RT->getDecl()->getDefinitionOrSelf();
933 if (!LookupQualifiedName(FieldResult, RD))
934 return true;
935
936 if (!FieldResult.isSingleResult())
937 return true;
938 FoundDecl = FieldResult.getFoundDecl();
939
940 // FIXME: Handle IndirectFieldDecl?
941 FieldDecl *FD = dyn_cast<FieldDecl>(FoundDecl);
942 if (!FD)
943 return true;
944
945 const ASTRecordLayout &RL = Context.getASTRecordLayout(RD);
946 unsigned i = FD->getFieldIndex();
947 CharUnits Result = Context.toCharUnitsFromBits(RL.getFieldOffset(i));
948 Offset += (unsigned)Result.getQuantity();
949 }
950
951 return false;
952}
953
956 SourceLocation AsmLoc) {
957
958 QualType T = E->getType();
959 if (T->isDependentType()) {
960 DeclarationNameInfo NameInfo;
961 NameInfo.setLoc(AsmLoc);
962 NameInfo.setName(&Context.Idents.get(Member));
964 Context, E, T, /*IsArrow=*/false, AsmLoc, NestedNameSpecifierLoc(),
966 /*FirstQualifierFoundInScope=*/nullptr, NameInfo, /*TemplateArgs=*/nullptr);
967 }
968
969 auto *RD = T->getAsRecordDecl();
970 // FIXME: Diagnose this as field access into a scalar type.
971 if (!RD)
972 return ExprResult();
973
974 LookupResult FieldResult(*this, &Context.Idents.get(Member), AsmLoc,
976
977 if (!LookupQualifiedName(FieldResult, RD))
978 return ExprResult();
979
980 // Only normal and indirect field results will work.
981 ValueDecl *FD = dyn_cast<FieldDecl>(FieldResult.getFoundDecl());
982 if (!FD)
983 FD = dyn_cast<IndirectFieldDecl>(FieldResult.getFoundDecl());
984 if (!FD)
985 return ExprResult();
986
987 // Make an Expr to thread through OpDecl.
989 E, E->getType(), AsmLoc, /*IsArrow=*/false, CXXScopeSpec(),
990 SourceLocation(), nullptr, FieldResult, nullptr, nullptr);
991
992 return Result;
993}
994
996 ArrayRef<Token> AsmToks,
997 StringRef AsmString,
998 unsigned NumOutputs, unsigned NumInputs,
999 ArrayRef<StringRef> Constraints,
1000 ArrayRef<StringRef> Clobbers,
1001 ArrayRef<Expr*> Exprs,
1002 SourceLocation EndLoc) {
1003 bool IsSimple = (NumOutputs != 0 || NumInputs != 0);
1005
1006 bool InvalidOperand = false;
1007 for (uint64_t I = 0; I < NumOutputs + NumInputs; ++I) {
1008 Expr *E = Exprs[I];
1009 if (E->getType()->isBitIntType()) {
1010 InvalidOperand = true;
1011 Diag(E->getBeginLoc(), diag::err_asm_invalid_type)
1012 << E->getType() << (I < NumOutputs)
1013 << E->getSourceRange();
1014 } else if (E->refersToBitField()) {
1015 InvalidOperand = true;
1016 FieldDecl *BitField = E->getSourceBitField();
1017 Diag(E->getBeginLoc(), diag::err_ms_asm_bitfield_unsupported)
1018 << E->getSourceRange();
1019 Diag(BitField->getLocation(), diag::note_bitfield_decl);
1020 }
1021 }
1022 if (InvalidOperand)
1023 return StmtError();
1024
1025 MSAsmStmt *NS =
1026 new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
1027 /*IsVolatile*/ true, AsmToks, NumOutputs, NumInputs,
1028 Constraints, Exprs, AsmString,
1029 Clobbers, EndLoc);
1030 return NS;
1031}
1032
1033LabelDecl *Sema::GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
1034 SourceLocation Location,
1035 bool AlwaysCreate) {
1036 LabelDecl* Label = LookupOrCreateLabel(PP.getIdentifierInfo(ExternalLabelName),
1037 Location);
1038
1039 if (Label->isMSAsmLabel()) {
1040 // If we have previously created this label implicitly, mark it as used.
1041 Label->markUsed(Context);
1042 } else {
1043 // Otherwise, insert it, but only resolve it if we have seen the label itself.
1044 std::string InternalName;
1045 llvm::raw_string_ostream OS(InternalName);
1046 // Create an internal name for the label. The name should not be a valid
1047 // mangled name, and should be unique. We use a dot to make the name an
1048 // invalid mangled name. We use LLVM's inline asm ${:uid} escape so that a
1049 // unique label is generated each time this blob is emitted, even after
1050 // inlining or LTO.
1051 OS << "__MSASMLABEL_.${:uid}__";
1052 for (char C : ExternalLabelName) {
1053 OS << C;
1054 // We escape '$' in asm strings by replacing it with "$$"
1055 if (C == '$')
1056 OS << '$';
1057 }
1058 Label->setMSAsmLabel(OS.str());
1059 }
1060 if (AlwaysCreate) {
1061 // The label might have been created implicitly from a previously encountered
1062 // goto statement. So, for both newly created and looked up labels, we mark
1063 // them as resolved.
1064 Label->setMSAsmLabelResolved();
1065 }
1066 // Adjust their location for being able to generate accurate diagnostics.
1067 Label->setLocation(Location);
1068
1069 return Label;
1070}
#define V(N, I)
Defines the clang::Expr interface and subclasses for C++ expressions.
llvm::MachO::Target Target
Definition MachO.h:51
Defines the clang::Preprocessor interface.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
static bool isOperandMentioned(unsigned OpNo, ArrayRef< GCCAsmStmt::AsmStringPiece > AsmStrPieces)
isOperandMentioned - Return true if the specified operand # is mentioned anywhere in the decomposed a...
static SourceLocation getClobberConflictLocation(MultiExprArg Exprs, Expr **Constraints, Expr **Clobbers, int NumClobbers, unsigned NumLabels, const TargetInfo &Target, ASTContext &Cont)
static bool CheckAsmLValue(Expr *E, Sema &S)
CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently ignore "noop" casts in p...
static StringRef extractRegisterName(const Expr *Expression, const TargetInfo &Target)
static bool CheckNakedParmReference(Expr *E, Sema &S)
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's memory constraint; false ot...
static void removeLValueToRValueCast(Expr *E)
Remove the upper-level LValueToRValue cast from an expression.
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...
Defines the clang::TypeLoc interface and its subclasses.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
APSInt & getInt()
Definition APValue.h:508
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition APValue.cpp:981
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
PtrTy get() const
Definition Ownership.h:171
bool isInvalid() const
Definition Ownership.h:167
Attr - This represents one attribute.
Definition Attr.h:46
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:1557
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:76
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3682
void setSubExpr(Expr *E)
Definition Expr.h:3734
Expr * getSubExpr()
Definition Expr.h:3732
SourceLocation getBegin() const
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1088
void SetResult(APValue Value, const ASTContext &Context)
Definition Expr.h:1149
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:356
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1276
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition DeclBase.cpp:591
SourceLocation getLocation() const
Definition DeclBase.h:447
void setLocation(SourceLocation L)
Definition DeclBase.h:448
This represents one expression.
Definition Expr.h:112
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
Definition Expr.cpp:3126
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 isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:447
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
Definition Expr.cpp:4292
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
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 ...
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...
bool isPRValue() const
Definition Expr.h:285
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Definition Expr.h:284
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
Definition Expr.cpp:4238
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...
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
Definition Expr.h:464
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
Definition Expr.h:479
isModifiableLvalueResult
Definition Expr.h:305
@ MLV_LValueCast
Definition Expr.h:312
@ MLV_IncompleteType
Definition Expr.h:313
@ MLV_Valid
Definition Expr.h:306
@ MLV_ArrayType
Definition Expr.h:317
@ MLV_IncompleteVoidType
Definition Expr.h:308
QualType getType() const
Definition Expr.h:144
bool refersToGlobalRegisterVar() const
Returns whether this expression refers to a global register variable.
Definition Expr.cpp:4317
ExprDependence getDependence() const
Definition Expr.h:164
Represents a member of a struct/union/class.
Definition Decl.h:3195
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3280
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:142
Represents a function declaration or definition.
Definition Decl.h:2027
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
Definition Stmt.h:3492
const std::string & getString() const
Definition Stmt.h:3517
unsigned getOperandNo() const
Definition Stmt.h:3519
CharSourceRange getRange() const
Definition Stmt.h:3524
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition Stmt.cpp:549
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3456
static std::string ExtractStringFromGCCAsmStmtComponent(const Expr *E)
Definition Stmt.cpp:554
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Represents the declaration of a label.
Definition Decl.h:524
void setMSAsmLabel(StringRef Name)
Definition Decl.cpp:5569
void setMSAsmLabelResolved()
Definition Decl.h:562
bool isMSAsmLabel() const
Definition Decl.h:558
Represents the results of name lookup.
Definition Lookup.h:147
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition Lookup.h:569
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition Lookup.h:331
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3675
This represents a decl that may have a name.
Definition Decl.h:274
A C++ nested-name-specifier augmented with source location information.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3392
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4360
RecordDecl * getDefinitionOrSelf() const
Definition Decl.h:4548
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:869
QualType getCurrentThisType()
Try to retrieve the type of the 'this' pointer.
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition Sema.h:1142
ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, ActOnMemberAccessExtraArgs *ExtraArgs=nullptr)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition Sema.h:9415
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9423
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)
void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl=nullptr, ExpressionEvaluationContextRecord::ExpressionKind Type=ExpressionEvaluationContextRecord::EK_Other)
void setFunctionHasBranchIntoScope()
Definition Sema.cpp:2608
ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool IsUnevaluatedContext)
ASTContext & Context
Definition Sema.h:1309
void CleanupVarDeclMarking()
ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, bool Diagnose=true)
Definition SemaExpr.cpp:761
ASTContext & getASTContext() const
Definition Sema.h:940
void PopExpressionEvaluationContext()
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition Sema.cpp:762
const LangOptions & getLangOpts() const
Definition Sema.h:933
bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type of the given expression is complete.
@ ReuseLambdaContextDecl
Definition Sema.h:7108
ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC=nullptr, bool IsInlineAsmIdentifier=false)
Preprocessor & PP
Definition Sema.h:1308
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
const LangOptions & LangOpts
Definition Sema.h:1307
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
DeclContext * getCurLexicalContext() const
Definition Sema.h:1146
bool EvaluateAsString(Expr *Message, APValue &Result, ASTContext &Ctx, StringEvaluationContext EvalContext, bool ErrorOnInvalidMessage)
SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, unsigned ByteNo) const
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1447
void FillInlineAsmIdentifierInfo(Expr *Res, llvm::InlineAsmIdentifierInfo &Info)
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset, SourceLocation AsmLoc)
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, SourceLocation AsmLoc)
void setFunctionHasBranchProtectedScope()
Definition Sema.cpp:2613
@ UnevaluatedAbstract
The current expression occurs within an unevaluated operand that unconditionally permits abstract ref...
Definition Sema.h:6813
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
void DiscardCleanupsInEvaluationContext()
LabelDecl * GetOrCreateMSAsmLabel(StringRef ExternalLabelName, SourceLocation Location, bool AlwaysCreate)
SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD=nullptr)
Definition Sema.cpp:2219
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel)
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
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)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Stmt - This represents one statement.
Definition Stmt.h:86
child_range children()
Definition Stmt.cpp:304
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
Exposes information about the current target.
Definition TargetInfo.h:227
Represents a declaration of a type.
Definition Decl.h:3548
The base class of the type hierarchy.
Definition TypeBase.h:1875
bool isVoidType() const
Definition TypeBase.h:9050
bool isBooleanType() const
Definition TypeBase.h:9187
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isPointerType() const
Definition TypeBase.h:8684
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition TypeBase.h:9094
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
bool isBitIntType() const
Definition TypeBase.h:8959
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2846
bool isMemberPointerType() const
Definition TypeBase.h:8765
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2531
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2409
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2985
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9277
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3597
Represents a C++ unqualified-id that has been parsed.
Definition DeclSpec.h:1039
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Represents a variable declaration or definition.
Definition Decl.h:932
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ CPlusPlus
@ SC_Register
Definition Specifiers.h:258
MutableArrayRef< Expr * > MultiExprArg
Definition Ownership.h:259
StmtResult StmtError()
Definition Ownership.h:266
@ Result
The result type of a method or function.
Definition TypeBase.h:905
ActionResult< CXXBaseSpecifier * > BaseResult
Definition Ownership.h:252
ExprResult ExprError()
Definition Ownership.h:265
CastKind
CastKind - The kind of operation required for a conversion.
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
ActionResult< Stmt * > StmtResult
Definition Ownership.h:250
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
EvalResult is a struct with detailed info about an evaluated expression.
Definition Expr.h:652
APValue Val
Val - This is the value the expression can be folded to.
Definition Expr.h:654
bool isGlobalLValue() const
Return true if the evaluated lvalue expression is global.
const std::string & getConstraintStr() const
bool isValidAsmImmediate(const llvm::APInt &Value) const
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand.