Coverage Report

Created: 2021-09-21 08:58

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