Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/AsmParser/LLParser.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- LLParser.cpp - Parser Class ---------------------------------------===//
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 defines the parser class for .ll files.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "LLParser.h"
14
#include "llvm/ADT/DenseMap.h"
15
#include "llvm/ADT/None.h"
16
#include "llvm/ADT/Optional.h"
17
#include "llvm/ADT/STLExtras.h"
18
#include "llvm/ADT/SmallPtrSet.h"
19
#include "llvm/AsmParser/SlotMapping.h"
20
#include "llvm/BinaryFormat/Dwarf.h"
21
#include "llvm/IR/Argument.h"
22
#include "llvm/IR/AutoUpgrade.h"
23
#include "llvm/IR/BasicBlock.h"
24
#include "llvm/IR/CallingConv.h"
25
#include "llvm/IR/Comdat.h"
26
#include "llvm/IR/Constants.h"
27
#include "llvm/IR/DebugInfoMetadata.h"
28
#include "llvm/IR/DerivedTypes.h"
29
#include "llvm/IR/Function.h"
30
#include "llvm/IR/GlobalIFunc.h"
31
#include "llvm/IR/GlobalObject.h"
32
#include "llvm/IR/InlineAsm.h"
33
#include "llvm/IR/Instruction.h"
34
#include "llvm/IR/Instructions.h"
35
#include "llvm/IR/Intrinsics.h"
36
#include "llvm/IR/LLVMContext.h"
37
#include "llvm/IR/Metadata.h"
38
#include "llvm/IR/Module.h"
39
#include "llvm/IR/Operator.h"
40
#include "llvm/IR/Type.h"
41
#include "llvm/IR/Value.h"
42
#include "llvm/IR/ValueSymbolTable.h"
43
#include "llvm/Support/Casting.h"
44
#include "llvm/Support/ErrorHandling.h"
45
#include "llvm/Support/MathExtras.h"
46
#include "llvm/Support/SaveAndRestore.h"
47
#include "llvm/Support/raw_ostream.h"
48
#include <algorithm>
49
#include <cassert>
50
#include <cstring>
51
#include <iterator>
52
#include <vector>
53
54
using namespace llvm;
55
56
79
static std::string getTypeString(Type *T) {
57
79
  std::string Result;
58
79
  raw_string_ostream Tmp(Result);
59
79
  Tmp << *T;
60
79
  return Tmp.str();
61
79
}
62
63
/// Run: module ::= toplevelentity*
64
37.9k
bool LLParser::Run() {
65
37.9k
  // Prime the lexer.
66
37.9k
  Lex.Lex();
67
37.9k
68
37.9k
  if (Context.shouldDiscardValueNames())
69
0
    return Error(
70
0
        Lex.getLoc(),
71
0
        "Can't read textual IR with a Context that discards named Values");
72
37.9k
73
37.9k
  return ParseTopLevelEntities() || 
ValidateEndOfModule()37.7k
||
74
37.9k
         
ValidateEndOfIndex()37.7k
;
75
37.9k
}
76
77
bool LLParser::parseStandaloneConstantValue(Constant *&C,
78
2.19k
                                            const SlotMapping *Slots) {
79
2.19k
  restoreParsingState(Slots);
80
2.19k
  Lex.Lex();
81
2.19k
82
2.19k
  Type *Ty = nullptr;
83
2.19k
  if (ParseType(Ty) || 
parseConstantValue(Ty, C)2.19k
)
84
5
    return true;
85
2.19k
  if (Lex.getKind() != lltok::Eof)
86
1
    return Error(Lex.getLoc(), "expected end of string");
87
2.18k
  return false;
88
2.18k
}
89
90
bool LLParser::parseTypeAtBeginning(Type *&Ty, unsigned &Read,
91
22
                                    const SlotMapping *Slots) {
92
22
  restoreParsingState(Slots);
93
22
  Lex.Lex();
94
22
95
22
  Read = 0;
96
22
  SMLoc Start = Lex.getLoc();
97
22
  Ty = nullptr;
98
22
  if (ParseType(Ty))
99
0
    return true;
100
22
  SMLoc End = Lex.getLoc();
101
22
  Read = End.getPointer() - Start.getPointer();
102
22
103
22
  return false;
104
22
}
105
106
2.21k
void LLParser::restoreParsingState(const SlotMapping *Slots) {
107
2.21k
  if (!Slots)
108
43
    return;
109
2.17k
  NumberedVals = Slots->GlobalValues;
110
2.17k
  NumberedMetadata = Slots->MetadataNodes;
111
2.17k
  for (const auto &I : Slots->NamedTypes)
112
55
    NamedTypes.insert(
113
55
        std::make_pair(I.getKey(), std::make_pair(I.second, LocTy())));
114
2.17k
  for (const auto &I : Slots->Types)
115
25
    NumberedTypes.insert(
116
25
        std::make_pair(I.first, std::make_pair(I.second, LocTy())));
117
2.17k
}
118
119
/// ValidateEndOfModule - Do final validity and sanity checks at the end of the
120
/// module.
121
37.7k
bool LLParser::ValidateEndOfModule() {
122
37.7k
  if (!M)
123
0
    return false;
124
37.7k
  // Handle any function attribute group forward references.
125
569k
  
for (const auto &RAG : ForwardRefAttrGroups)37.7k
{
126
569k
    Value *V = RAG.first;
127
569k
    const std::vector<unsigned> &Attrs = RAG.second;
128
569k
    AttrBuilder B;
129
569k
130
569k
    for (const auto &Attr : Attrs)
131
66.3k
      B.merge(NumberedAttrBuilders[Attr]);
132
569k
133
569k
    if (Function *Fn = dyn_cast<Function>(V)) {
134
378k
      AttributeList AS = Fn->getAttributes();
135
378k
      AttrBuilder FnAttrs(AS.getFnAttributes());
136
378k
      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
137
378k
138
378k
      FnAttrs.merge(B);
139
378k
140
378k
      // If the alignment was parsed as an attribute, move to the alignment
141
378k
      // field.
142
378k
      if (FnAttrs.hasAlignmentAttr()) {
143
0
        Fn->setAlignment(FnAttrs.getAlignment());
144
0
        FnAttrs.removeAttribute(Attribute::Alignment);
145
0
      }
146
378k
147
378k
      AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
148
378k
                            AttributeSet::get(Context, FnAttrs));
149
378k
      Fn->setAttributes(AS);
150
378k
    } else 
if (CallInst *191k
CI191k
= dyn_cast<CallInst>(V)) {
151
188k
      AttributeList AS = CI->getAttributes();
152
188k
      AttrBuilder FnAttrs(AS.getFnAttributes());
153
188k
      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
154
188k
      FnAttrs.merge(B);
155
188k
      AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
156
188k
                            AttributeSet::get(Context, FnAttrs));
157
188k
      CI->setAttributes(AS);
158
188k
    } else 
if (InvokeInst *2.23k
II2.23k
= dyn_cast<InvokeInst>(V)) {
159
2.17k
      AttributeList AS = II->getAttributes();
160
2.17k
      AttrBuilder FnAttrs(AS.getFnAttributes());
161
2.17k
      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
162
2.17k
      FnAttrs.merge(B);
163
2.17k
      AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
164
2.17k
                            AttributeSet::get(Context, FnAttrs));
165
2.17k
      II->setAttributes(AS);
166
2.17k
    } else 
if (CallBrInst *64
CBI64
= dyn_cast<CallBrInst>(V)) {
167
26
      AttributeList AS = CBI->getAttributes();
168
26
      AttrBuilder FnAttrs(AS.getFnAttributes());
169
26
      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
170
26
      FnAttrs.merge(B);
171
26
      AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
172
26
                            AttributeSet::get(Context, FnAttrs));
173
26
      CBI->setAttributes(AS);
174
38
    } else if (auto *GV = dyn_cast<GlobalVariable>(V)) {
175
38
      AttrBuilder Attrs(GV->getAttributes());
176
38
      Attrs.merge(B);
177
38
      GV->setAttributes(AttributeSet::get(Context,Attrs));
178
38
    } else {
179
0
      llvm_unreachable("invalid object with forward attribute group reference");
180
0
    }
181
569k
  }
182
37.7k
183
37.7k
  // If there are entries in ForwardRefBlockAddresses at this point, the
184
37.7k
  // function was never defined.
185
37.7k
  if (!ForwardRefBlockAddresses.empty())
186
0
    return Error(ForwardRefBlockAddresses.begin()->first.Loc,
187
0
                 "expected function name in blockaddress");
188
37.7k
189
37.7k
  for (const auto &NT : NumberedTypes)
190
675
    if (NT.second.second.isValid())
191
0
      return Error(NT.second.second,
192
0
                   "use of undefined type '%" + Twine(NT.first) + "'");
193
37.7k
194
37.7k
  for (StringMap<std::pair<Type*, LocTy> >::iterator I =
195
50.3k
       NamedTypes.begin(), E = NamedTypes.end(); I != E; 
++I12.6k
)
196
12.6k
    if (I->second.second.isValid())
197
2
      return Error(I->second.second,
198
2
                   "use of undefined type named '" + I->getKey() + "'");
199
37.7k
200
37.7k
  
if (37.7k
!ForwardRefComdats.empty()37.7k
)
201
1
    return Error(ForwardRefComdats.begin()->second,
202
1
                 "use of undefined comdat '$" +
203
1
                     ForwardRefComdats.begin()->first + "'");
204
37.7k
205
37.7k
  if (!ForwardRefVals.empty())
206
1
    return Error(ForwardRefVals.begin()->second.second,
207
1
                 "use of undefined value '@" + ForwardRefVals.begin()->first +
208
1
                 "'");
209
37.7k
210
37.7k
  if (!ForwardRefValIDs.empty())
211
0
    return Error(ForwardRefValIDs.begin()->second.second,
212
0
                 "use of undefined value '@" +
213
0
                 Twine(ForwardRefValIDs.begin()->first) + "'");
214
37.7k
215
37.7k
  if (!ForwardRefMDNodes.empty())
216
3
    return Error(ForwardRefMDNodes.begin()->second.second,
217
3
                 "use of undefined metadata '!" +
218
3
                 Twine(ForwardRefMDNodes.begin()->first) + "'");
219
37.7k
220
37.7k
  // Resolve metadata cycles.
221
72.7k
  
for (auto &N : NumberedMetadata)37.7k
{
222
72.7k
    if (N.second && !N.second->isResolved())
223
179
      N.second->resolveCycles();
224
72.7k
  }
225
37.7k
226
37.7k
  for (auto *Inst : InstsWithTBAATag) {
227
4.63k
    MDNode *MD = Inst->getMetadata(LLVMContext::MD_tbaa);
228
4.63k
    assert(MD && "UpgradeInstWithTBAATag should have a TBAA tag");
229
4.63k
    auto *UpgradedMD = UpgradeTBAANode(*MD);
230
4.63k
    if (MD != UpgradedMD)
231
194
      Inst->setMetadata(LLVMContext::MD_tbaa, UpgradedMD);
232
4.63k
  }
233
37.7k
234
37.7k
  // Look for intrinsic functions and CallInst that need to be upgraded
235
418k
  for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
236
380k
    UpgradeCallsToIntrinsic(&*FI++); // must be post-increment, as we remove
237
37.7k
238
37.7k
  // Some types could be renamed during loading if several modules are
239
37.7k
  // loaded in the same LLVMContext (LTO scenario). In this case we should
240
37.7k
  // remangle intrinsics names as well.
241
413k
  for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ) {
242
375k
    Function *F = &*FI++;
243
375k
    if (auto Remangled = Intrinsic::remangleIntrinsicFunction(F)) {
244
2
      F->replaceAllUsesWith(Remangled.getValue());
245
2
      F->eraseFromParent();
246
2
    }
247
375k
  }
248
37.7k
249
37.7k
  if (UpgradeDebugInfo)
250
13.7k
    llvm::UpgradeDebugInfo(*M);
251
37.7k
252
37.7k
  UpgradeModuleFlags(*M);
253
37.7k
  UpgradeSectionAttributes(*M);
254
37.7k
255
37.7k
  if (!Slots)
256
36.6k
    return false;
257
1.13k
  // Initialize the slot mapping.
258
1.13k
  // Because by this point we've parsed and validated everything, we can "steal"
259
1.13k
  // the mapping from LLParser as it doesn't need it anymore.
260
1.13k
  Slots->GlobalValues = std::move(NumberedVals);
261
1.13k
  Slots->MetadataNodes = std::move(NumberedMetadata);
262
1.13k
  for (const auto &I : NamedTypes)
263
91
    Slots->NamedTypes.insert(std::make_pair(I.getKey(), I.second.first));
264
1.13k
  for (const auto &I : NumberedTypes)
265
16
    Slots->Types.insert(std::make_pair(I.first, I.second.first));
266
1.13k
267
1.13k
  return false;
268
1.13k
}
269
270
/// Do final validity and sanity checks at the end of the index.
271
37.7k
bool LLParser::ValidateEndOfIndex() {
272
37.7k
  if (!Index)
273
36.7k
    return false;
274
1.01k
275
1.01k
  if (!ForwardRefValueInfos.empty())
276
0
    return Error(ForwardRefValueInfos.begin()->second.front().second,
277
0
                 "use of undefined summary '^" +
278
0
                     Twine(ForwardRefValueInfos.begin()->first) + "'");
279
1.01k
280
1.01k
  if (!ForwardRefAliasees.empty())
281
0
    return Error(ForwardRefAliasees.begin()->second.front().second,
282
0
                 "use of undefined summary '^" +
283
0
                     Twine(ForwardRefAliasees.begin()->first) + "'");
284
1.01k
285
1.01k
  if (!ForwardRefTypeIds.empty())
286
0
    return Error(ForwardRefTypeIds.begin()->second.front().second,
287
0
                 "use of undefined type id summary '^" +
288
0
                     Twine(ForwardRefTypeIds.begin()->first) + "'");
289
1.01k
290
1.01k
  return false;
291
1.01k
}
292
293
//===----------------------------------------------------------------------===//
294
// Top-Level Entities
295
//===----------------------------------------------------------------------===//
296
297
37.9k
bool LLParser::ParseTopLevelEntities() {
298
37.9k
  // If there is no Module, then parse just the summary index entries.
299
37.9k
  if (!M) {
300
0
    while (true) {
301
0
      switch (Lex.getKind()) {
302
0
      case lltok::Eof:
303
0
        return false;
304
0
      case lltok::SummaryID:
305
0
        if (ParseSummaryEntry())
306
0
          return true;
307
0
        break;
308
0
      case lltok::kw_source_filename:
309
0
        if (ParseSourceFileName())
310
0
          return true;
311
0
        break;
312
0
      default:
313
0
        // Skip everything else
314
0
        Lex.Lex();
315
0
      }
316
0
    }
317
0
  }
318
569k
  
while (37.9k
true) {
319
569k
    switch (Lex.getKind()) {
320
569k
    
default: return TokError("expected top-level entity")3
;
321
569k
    
case lltok::Eof: return false37.7k
;
322
569k
    
case lltok::kw_declare: if (81.3k
ParseDeclare()81.3k
)
return true11
; break;
323
297k
    case lltok::kw_define:  if (ParseDefine()) 
return true91
; break;
324
297k
    
case lltok::kw_module: if (341
ParseModuleAsm()341
)
return true0
; break;
325
14.0k
    case lltok::kw_target:  if (ParseTargetDefinition()) 
return true0
; break;
326
14.0k
    case lltok::kw_source_filename:
327
1.78k
      if (ParseSourceFileName())
328
0
        return true;
329
1.78k
      break;
330
1.78k
    
case lltok::kw_deplibs: if (0
ParseDepLibs()0
)
return true0
; break;
331
675
    case lltok::LocalVarID: if (ParseUnnamedType()) 
return true0
; break;
332
12.6k
    case lltok::LocalVar:   if (ParseNamedType()) 
return true2
; break;
333
12.6k
    
case lltok::GlobalID: if (695
ParseUnnamedGlobal()695
)
return true6
; break;
334
30.8k
    case lltok::GlobalVar:  if (ParseNamedGlobal()) 
return true24
; break;
335
30.8k
    
case lltok::ComdatVar: if (812
parseComdat()812
)
return true1
; break;
336
72.8k
    case lltok::exclaim:    if (ParseStandaloneMetadata()) 
return true54
; break;
337
72.7k
    case lltok::SummaryID:
338
157
      if (ParseSummaryEntry())
339
3
        return true;
340
154
      break;
341
6.83k
    case lltok::MetadataVar:if (ParseNamedMetadata()) 
return true0
; break;
342
10.8k
    case lltok::kw_attributes: if (ParseUnnamedAttrGrp()) 
return true1
; break;
343
10.8k
    
case lltok::kw_uselistorder: if (127
ParseUseListOrder()127
)
return true10
; break;
344
117
    case lltok::kw_uselistorder_bb:
345
12
      if (ParseUseListOrderBB())
346
6
        return true;
347
6
      break;
348
569k
    }
349
569k
  }
350
37.9k
}
351
352
/// toplevelentity
353
///   ::= 'module' 'asm' STRINGCONSTANT
354
341
bool LLParser::ParseModuleAsm() {
355
341
  assert(Lex.getKind() == lltok::kw_module);
356
341
  Lex.Lex();
357
341
358
341
  std::string AsmStr;
359
341
  if (ParseToken(lltok::kw_asm, "expected 'module asm'") ||
360
341
      ParseStringConstant(AsmStr)) 
return true0
;
361
341
362
341
  M->appendModuleInlineAsm(AsmStr);
363
341
  return false;
364
341
}
365
366
/// toplevelentity
367
///   ::= 'target' 'triple' '=' STRINGCONSTANT
368
///   ::= 'target' 'datalayout' '=' STRINGCONSTANT
369
14.0k
bool LLParser::ParseTargetDefinition() {
370
14.0k
  assert(Lex.getKind() == lltok::kw_target);
371
14.0k
  std::string Str;
372
14.0k
  switch (Lex.Lex()) {
373
14.0k
  
default: return TokError("unknown target property")0
;
374
14.0k
  case lltok::kw_triple:
375
6.23k
    Lex.Lex();
376
6.23k
    if (ParseToken(lltok::equal, "expected '=' after target triple") ||
377
6.23k
        ParseStringConstant(Str))
378
0
      return true;
379
6.23k
    M->setTargetTriple(Str);
380
6.23k
    return false;
381
7.83k
  case lltok::kw_datalayout:
382
7.83k
    Lex.Lex();
383
7.83k
    if (ParseToken(lltok::equal, "expected '=' after target datalayout") ||
384
7.83k
        ParseStringConstant(Str))
385
0
      return true;
386
7.83k
    if (DataLayoutStr.empty())
387
7.83k
      M->setDataLayout(Str);
388
7.83k
    return false;
389
14.0k
  }
390
14.0k
}
391
392
/// toplevelentity
393
///   ::= 'source_filename' '=' STRINGCONSTANT
394
1.78k
bool LLParser::ParseSourceFileName() {
395
1.78k
  assert(Lex.getKind() == lltok::kw_source_filename);
396
1.78k
  Lex.Lex();
397
1.78k
  if (ParseToken(lltok::equal, "expected '=' after source_filename") ||
398
1.78k
      ParseStringConstant(SourceFileName))
399
0
    return true;
400
1.78k
  if (M)
401
1.78k
    M->setSourceFileName(SourceFileName);
402
1.78k
  return false;
403
1.78k
}
404
405
/// toplevelentity
406
///   ::= 'deplibs' '=' '[' ']'
407
///   ::= 'deplibs' '=' '[' STRINGCONSTANT (',' STRINGCONSTANT)* ']'
408
/// FIXME: Remove in 4.0. Currently parse, but ignore.
409
0
bool LLParser::ParseDepLibs() {
410
0
  assert(Lex.getKind() == lltok::kw_deplibs);
411
0
  Lex.Lex();
412
0
  if (ParseToken(lltok::equal, "expected '=' after deplibs") ||
413
0
      ParseToken(lltok::lsquare, "expected '=' after deplibs"))
414
0
    return true;
415
0
416
0
  if (EatIfPresent(lltok::rsquare))
417
0
    return false;
418
0
419
0
  do {
420
0
    std::string Str;
421
0
    if (ParseStringConstant(Str)) return true;
422
0
  } while (EatIfPresent(lltok::comma));
423
0
424
0
  return ParseToken(lltok::rsquare, "expected ']' at end of list");
425
0
}
426
427
/// ParseUnnamedType:
428
///   ::= LocalVarID '=' 'type' type
429
675
bool LLParser::ParseUnnamedType() {
430
675
  LocTy TypeLoc = Lex.getLoc();
431
675
  unsigned TypeID = Lex.getUIntVal();
432
675
  Lex.Lex(); // eat LocalVarID;
433
675
434
675
  if (ParseToken(lltok::equal, "expected '=' after name") ||
435
675
      ParseToken(lltok::kw_type, "expected 'type' after '='"))
436
0
    return true;
437
675
438
675
  Type *Result = nullptr;
439
675
  if (ParseStructDefinition(TypeLoc, "",
440
675
                            NumberedTypes[TypeID], Result)) 
return true0
;
441
675
442
675
  if (!isa<StructType>(Result)) {
443
4
    std::pair<Type*, LocTy> &Entry = NumberedTypes[TypeID];
444
4
    if (Entry.first)
445
0
      return Error(TypeLoc, "non-struct types may not be recursive");
446
4
    Entry.first = Result;
447
4
    Entry.second = SMLoc();
448
4
  }
449
675
450
675
  return false;
451
675
}
452
453
/// toplevelentity
454
///   ::= LocalVar '=' 'type' type
455
12.6k
bool LLParser::ParseNamedType() {
456
12.6k
  std::string Name = Lex.getStrVal();
457
12.6k
  LocTy NameLoc = Lex.getLoc();
458
12.6k
  Lex.Lex();  // eat LocalVar.
459
12.6k
460
12.6k
  if (ParseToken(lltok::equal, "expected '=' after name") ||
461
12.6k
      ParseToken(lltok::kw_type, "expected 'type' after name"))
462
0
    return true;
463
12.6k
464
12.6k
  Type *Result = nullptr;
465
12.6k
  if (ParseStructDefinition(NameLoc, Name,
466
12.6k
                            NamedTypes[Name], Result)) 
return true2
;
467
12.6k
468
12.6k
  if (!isa<StructType>(Result)) {
469
701
    std::pair<Type*, LocTy> &Entry = NamedTypes[Name];
470
701
    if (Entry.first)
471
0
      return Error(NameLoc, "non-struct types may not be recursive");
472
701
    Entry.first = Result;
473
701
    Entry.second = SMLoc();
474
701
  }
475
12.6k
476
12.6k
  return false;
477
12.6k
}
478
479
/// toplevelentity
480
///   ::= 'declare' FunctionHeader
481
81.3k
bool LLParser::ParseDeclare() {
482
81.3k
  assert(Lex.getKind() == lltok::kw_declare);
483
81.3k
  Lex.Lex();
484
81.3k
485
81.3k
  std::vector<std::pair<unsigned, MDNode *>> MDs;
486
81.4k
  while (Lex.getKind() == lltok::MetadataVar) {
487
53
    unsigned MDK;
488
53
    MDNode *N;
489
53
    if (ParseMetadataAttachment(MDK, N))
490
0
      return true;
491
53
    MDs.push_back({MDK, N});
492
53
  }
493
81.3k
494
81.3k
  Function *F;
495
81.3k
  if (ParseFunctionHeader(F, false))
496
11
    return true;
497
81.3k
  for (auto &MD : MDs)
498
53
    F->addMetadata(MD.first, *MD.second);
499
81.3k
  return false;
500
81.3k
}
501
502
/// toplevelentity
503
///   ::= 'define' FunctionHeader (!dbg !56)* '{' ...
504
297k
bool LLParser::ParseDefine() {
505
297k
  assert(Lex.getKind() == lltok::kw_define);
506
297k
  Lex.Lex();
507
297k
508
297k
  Function *F;
509
297k
  return ParseFunctionHeader(F, true) ||
510
297k
         
ParseOptionalFunctionMetadata(*F)297k
||
511
297k
         
ParseFunctionBody(*F)297k
;
512
297k
}
513
514
/// ParseGlobalType
515
///   ::= 'constant'
516
///   ::= 'global'
517
30.5k
bool LLParser::ParseGlobalType(bool &IsConstant) {
518
30.5k
  if (Lex.getKind() == lltok::kw_constant)
519
5.16k
    IsConstant = true;
520
25.3k
  else if (Lex.getKind() == lltok::kw_global)
521
25.3k
    IsConstant = false;
522
0
  else {
523
0
    IsConstant = false;
524
0
    return TokError("expected 'global' or 'constant'");
525
0
  }
526
30.5k
  Lex.Lex();
527
30.5k
  return false;
528
30.5k
}
529
530
bool LLParser::ParseOptionalUnnamedAddr(
531
410k
    GlobalVariable::UnnamedAddr &UnnamedAddr) {
532
410k
  if (EatIfPresent(lltok::kw_unnamed_addr))
533
3.41k
    UnnamedAddr = GlobalValue::UnnamedAddr::Global;
534
406k
  else if (EatIfPresent(lltok::kw_local_unnamed_addr))
535
6.99k
    UnnamedAddr = GlobalValue::UnnamedAddr::Local;
536
399k
  else
537
399k
    UnnamedAddr = GlobalValue::UnnamedAddr::None;
538
410k
  return false;
539
410k
}
540
541
/// ParseUnnamedGlobal:
542
///   OptionalVisibility (ALIAS | IFUNC) ...
543
///   OptionalLinkage OptionalPreemptionSpecifier OptionalVisibility
544
///   OptionalDLLStorageClass
545
///                                                     ...   -> global variable
546
///   GlobalID '=' OptionalVisibility (ALIAS | IFUNC) ...
547
///   GlobalID '=' OptionalLinkage OptionalPreemptionSpecifier OptionalVisibility
548
///                OptionalDLLStorageClass
549
///                                                     ...   -> global variable
550
695
bool LLParser::ParseUnnamedGlobal() {
551
695
  unsigned VarID = NumberedVals.size();
552
695
  std::string Name;
553
695
  LocTy NameLoc = Lex.getLoc();
554
695
555
695
  // Handle the GlobalID form.
556
695
  if (Lex.getKind() == lltok::GlobalID) {
557
695
    if (Lex.getUIntVal() != VarID)
558
0
      return Error(Lex.getLoc(), "variable expected to be numbered '%" +
559
0
                   Twine(VarID) + "'");
560
695
    Lex.Lex(); // eat GlobalID;
561
695
562
695
    if (ParseToken(lltok::equal, "expected '=' after name"))
563
0
      return true;
564
695
  }
565
695
566
695
  bool HasLinkage;
567
695
  unsigned Linkage, Visibility, DLLStorageClass;
568
695
  bool DSOLocal;
569
695
  GlobalVariable::ThreadLocalMode TLM;
570
695
  GlobalVariable::UnnamedAddr UnnamedAddr;
571
695
  if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
572
695
                           DSOLocal) ||
573
695
      ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
574
0
    return true;
575
695
576
695
  if (Lex.getKind() != lltok::kw_alias && 
Lex.getKind() != lltok::kw_ifunc691
)
577
691
    return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
578
691
                       DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
579
4
580
4
  return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
581
4
                             DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
582
4
}
583
584
/// ParseNamedGlobal:
585
///   GlobalVar '=' OptionalVisibility (ALIAS | IFUNC) ...
586
///   GlobalVar '=' OptionalLinkage OptionalPreemptionSpecifier
587
///                 OptionalVisibility OptionalDLLStorageClass
588
///                                                     ...   -> global variable
589
30.8k
bool LLParser::ParseNamedGlobal() {
590
30.8k
  assert(Lex.getKind() == lltok::GlobalVar);
591
30.8k
  LocTy NameLoc = Lex.getLoc();
592
30.8k
  std::string Name = Lex.getStrVal();
593
30.8k
  Lex.Lex();
594
30.8k
595
30.8k
  bool HasLinkage;
596
30.8k
  unsigned Linkage, Visibility, DLLStorageClass;
597
30.8k
  bool DSOLocal;
598
30.8k
  GlobalVariable::ThreadLocalMode TLM;
599
30.8k
  GlobalVariable::UnnamedAddr UnnamedAddr;
600
30.8k
  if (ParseToken(lltok::equal, "expected '=' in global variable") ||
601
30.8k
      ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
602
30.8k
                           DSOLocal) ||
603
30.8k
      
ParseOptionalThreadLocal(TLM)30.8k
||
ParseOptionalUnnamedAddr(UnnamedAddr)30.8k
)
604
1
    return true;
605
30.8k
606
30.8k
  if (Lex.getKind() != lltok::kw_alias && 
Lex.getKind() != lltok::kw_ifunc29.8k
)
607
29.8k
    return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
608
29.8k
                       DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
609
1.04k
610
1.04k
  return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
611
1.04k
                             DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
612
1.04k
}
613
614
812
bool LLParser::parseComdat() {
615
812
  assert(Lex.getKind() == lltok::ComdatVar);
616
812
  std::string Name = Lex.getStrVal();
617
812
  LocTy NameLoc = Lex.getLoc();
618
812
  Lex.Lex();
619
812
620
812
  if (ParseToken(lltok::equal, "expected '=' here"))
621
0
    return true;
622
812
623
812
  if (ParseToken(lltok::kw_comdat, "expected comdat keyword"))
624
0
    return TokError("expected comdat type");
625
812
626
812
  Comdat::SelectionKind SK;
627
812
  switch (Lex.getKind()) {
628
812
  default:
629
0
    return TokError("unknown selection kind");
630
812
  case lltok::kw_any:
631
726
    SK = Comdat::Any;
632
726
    break;
633
812
  case lltok::kw_exactmatch:
634
5
    SK = Comdat::ExactMatch;
635
5
    break;
636
812
  case lltok::kw_largest:
637
67
    SK = Comdat::Largest;
638
67
    break;
639
812
  case lltok::kw_noduplicates:
640
7
    SK = Comdat::NoDuplicates;
641
7
    break;
642
812
  case lltok::kw_samesize:
643
7
    SK = Comdat::SameSize;
644
7
    break;
645
812
  }
646
812
  Lex.Lex();
647
812
648
812
  // See if the comdat was forward referenced, if so, use the comdat.
649
812
  Module::ComdatSymTabType &ComdatSymTab = M->getComdatSymbolTable();
650
812
  Module::ComdatSymTabType::iterator I = ComdatSymTab.find(Name);
651
812
  if (I != ComdatSymTab.end() && 
!ForwardRefComdats.erase(Name)2
)
652
1
    return Error(NameLoc, "redefinition of comdat '$" + Name + "'");
653
811
654
811
  Comdat *C;
655
811
  if (I != ComdatSymTab.end())
656
1
    C = &I->second;
657
810
  else
658
810
    C = M->getOrInsertComdat(Name);
659
811
  C->setSelectionKind(SK);
660
811
661
811
  return false;
662
811
}
663
664
// MDString:
665
//   ::= '!' STRINGCONSTANT
666
17.6k
bool LLParser::ParseMDString(MDString *&Result) {
667
17.6k
  std::string Str;
668
17.6k
  if (ParseStringConstant(Str)) 
return true0
;
669
17.6k
  Result = MDString::get(Context, Str);
670
17.6k
  return false;
671
17.6k
}
672
673
// MDNode:
674
//   ::= '!' MDNodeNumber
675
153k
bool LLParser::ParseMDNodeID(MDNode *&Result) {
676
153k
  // !{ ..., !42, ... }
677
153k
  LocTy IDLoc = Lex.getLoc();
678
153k
  unsigned MID = 0;
679
153k
  if (ParseUInt32(MID))
680
0
    return true;
681
153k
682
153k
  // If not a forward reference, just return it now.
683
153k
  if (NumberedMetadata.count(MID)) {
684
83.0k
    Result = NumberedMetadata[MID];
685
83.0k
    return false;
686
83.0k
  }
687
70.7k
688
70.7k
  // Otherwise, create MDNode forward reference.
689
70.7k
  auto &FwdRef = ForwardRefMDNodes[MID];
690
70.7k
  FwdRef = std::make_pair(MDTuple::getTemporary(Context, None), IDLoc);
691
70.7k
692
70.7k
  Result = FwdRef.first.get();
693
70.7k
  NumberedMetadata[MID].reset(Result);
694
70.7k
  return false;
695
70.7k
}
696
697
/// ParseNamedMetadata:
698
///   !foo = !{ !1, !2 }
699
6.83k
bool LLParser::ParseNamedMetadata() {
700
6.83k
  assert(Lex.getKind() == lltok::MetadataVar);
701
6.83k
  std::string Name = Lex.getStrVal();
702
6.83k
  Lex.Lex();
703
6.83k
704
6.83k
  if (ParseToken(lltok::equal, "expected '=' here") ||
705
6.83k
      ParseToken(lltok::exclaim, "Expected '!' here") ||
706
6.83k
      ParseToken(lltok::lbrace, "Expected '{' here"))
707
0
    return true;
708
6.83k
709
6.83k
  NamedMDNode *NMD = M->getOrInsertNamedMetadata(Name);
710
6.83k
  if (Lex.getKind() != lltok::rbrace)
711
12.2k
    
do 6.82k
{
712
12.2k
      MDNode *N = nullptr;
713
12.2k
      // Parse DIExpressions inline as a special case. They are still MDNodes,
714
12.2k
      // so they can still appear in named metadata. Remove this logic if they
715
12.2k
      // become plain Metadata.
716
12.2k
      if (Lex.getKind() == lltok::MetadataVar &&
717
12.2k
          
Lex.getStrVal() == "DIExpression"50
) {
718
50
        if (ParseDIExpression(N, /*IsDistinct=*/false))
719
0
          return true;
720
12.1k
      } else if (ParseToken(lltok::exclaim, "Expected '!' here") ||
721
12.1k
                 ParseMDNodeID(N)) {
722
0
        return true;
723
0
      }
724
12.2k
      NMD->addOperand(N);
725
12.2k
    } while (EatIfPresent(lltok::comma));
726
6.83k
727
6.83k
  return ParseToken(lltok::rbrace, "expected end of metadata node");
728
6.83k
}
729
730
/// ParseStandaloneMetadata:
731
///   !42 = !{...}
732
72.8k
bool LLParser::ParseStandaloneMetadata() {
733
72.8k
  assert(Lex.getKind() == lltok::exclaim);
734
72.8k
  Lex.Lex();
735
72.8k
  unsigned MetadataID = 0;
736
72.8k
737
72.8k
  MDNode *Init;
738
72.8k
  if (ParseUInt32(MetadataID) ||
739
72.8k
      ParseToken(lltok::equal, "expected '=' here"))
740
0
    return true;
741
72.8k
742
72.8k
  // Detect common error, from old metadata syntax.
743
72.8k
  if (Lex.getKind() == lltok::Type)
744
1
    return TokError("unexpected type in metadata definition");
745
72.8k
746
72.8k
  bool IsDistinct = EatIfPresent(lltok::kw_distinct);
747
72.8k
  if (Lex.getKind() == lltok::MetadataVar) {
748
48.4k
    if (ParseSpecializedMDNode(Init, IsDistinct))
749
50
      return true;
750
24.4k
  } else if (ParseToken(lltok::exclaim, "Expected '!' here") ||
751
24.4k
             ParseMDTuple(Init, IsDistinct))
752
3
    return true;
753
72.7k
754
72.7k
  // See if this was forward referenced, if so, handle it.
755
72.7k
  auto FI = ForwardRefMDNodes.find(MetadataID);
756
72.7k
  if (FI != ForwardRefMDNodes.end()) {
757
70.7k
    FI->second.first->replaceAllUsesWith(Init);
758
70.7k
    ForwardRefMDNodes.erase(FI);
759
70.7k
760
70.7k
    assert(NumberedMetadata[MetadataID] == Init && "Tracking VH didn't work");
761
70.7k
  } else {
762
1.98k
    if (NumberedMetadata.count(MetadataID))
763
0
      return TokError("Metadata id is already used");
764
1.98k
    NumberedMetadata[MetadataID].reset(Init);
765
1.98k
  }
766
72.7k
767
72.7k
  return false;
768
72.7k
}
769
770
// Skips a single module summary entry.
771
6
bool LLParser::SkipModuleSummaryEntry() {
772
6
  // Each module summary entry consists of a tag for the entry
773
6
  // type, followed by a colon, then the fields surrounded by nested sets of
774
6
  // parentheses. The "tag:" looks like a Label. Once parsing support is
775
6
  // in place we will look for the tokens corresponding to the expected tags.
776
6
  if (Lex.getKind() != lltok::kw_gv && 
Lex.getKind() != lltok::kw_module4
&&
777
6
      
Lex.getKind() != lltok::kw_typeid1
)
778
1
    return TokError(
779
1
        "Expected 'gv', 'module', or 'typeid' at the start of summary entry");
780
5
  Lex.Lex();
781
5
  if (ParseToken(lltok::colon, "expected ':' at start of summary entry") ||
782
5
      ParseToken(lltok::lparen, "expected '(' at start of summary entry"))
783
1
    return true;
784
4
  // Now walk through the parenthesized entry, until the number of open
785
4
  // parentheses goes back down to 0 (the first '(' was parsed above).
786
4
  unsigned NumOpenParen = 1;
787
94
  do {
788
94
    switch (Lex.getKind()) {
789
94
    case lltok::lparen:
790
6
      NumOpenParen++;
791
6
      break;
792
94
    case lltok::rparen:
793
9
      NumOpenParen--;
794
9
      break;
795
94
    case lltok::Eof:
796
1
      return TokError("found end of file while parsing summary entry");
797
94
    default:
798
78
      // Skip everything in between parentheses.
799
78
      break;
800
93
    }
801
93
    Lex.Lex();
802
93
  } while (NumOpenParen > 0);
803
4
  
return false3
;
804
4
}
805
806
/// SummaryEntry
807
///   ::= SummaryID '=' GVEntry | ModuleEntry | TypeIdEntry
808
157
bool LLParser::ParseSummaryEntry() {
809
157
  assert(Lex.getKind() == lltok::SummaryID);
810
157
  unsigned SummaryID = Lex.getUIntVal();
811
157
812
157
  // For summary entries, colons should be treated as distinct tokens,
813
157
  // not an indication of the end of a label token.
814
157
  Lex.setIgnoreColonInIdentifiers(true);
815
157
816
157
  Lex.Lex();
817
157
  if (ParseToken(lltok::equal, "expected '=' here"))
818
0
    return true;
819
157
820
157
  // If we don't have an index object, skip the summary entry.
821
157
  if (!Index)
822
6
    return SkipModuleSummaryEntry();
823
151
824
151
  bool result = false;
825
151
  switch (Lex.getKind()) {
826
151
  case lltok::kw_gv:
827
116
    result = ParseGVEntry(SummaryID);
828
116
    break;
829
151
  case lltok::kw_module:
830
24
    result = ParseModuleEntry(SummaryID);
831
24
    break;
832
151
  case lltok::kw_typeid:
833
7
    result = ParseTypeIdEntry(SummaryID);
834
7
    break;
835
151
  case lltok::kw_typeidCompatibleVTable:
836
4
    result = ParseTypeIdCompatibleVtableEntry(SummaryID);
837
4
    break;
838
151
  default:
839
0
    result = Error(Lex.getLoc(), "unexpected summary kind");
840
0
    break;
841
151
  }
842
151
  Lex.setIgnoreColonInIdentifiers(false);
843
151
  return result;
844
151
}
845
846
410k
static bool isValidVisibilityForLinkage(unsigned V, unsigned L) {
847
410k
  return !GlobalValue::isLocalLinkage((GlobalValue::LinkageTypes)L) ||
848
410k
         
(GlobalValue::VisibilityTypes)V == GlobalValue::DefaultVisibility6.08k
;
849
410k
}
850
851
// If there was an explicit dso_local, update GV. In the absence of an explicit
852
// dso_local we keep the default value.
853
410k
static void maybeSetDSOLocal(bool DSOLocal, GlobalValue &GV) {
854
410k
  if (DSOLocal)
855
2.88k
    GV.setDSOLocal(true);
856
410k
}
857
858
/// parseIndirectSymbol:
859
///   ::= GlobalVar '=' OptionalLinkage OptionalPreemptionSpecifier
860
///                     OptionalVisibility OptionalDLLStorageClass
861
///                     OptionalThreadLocal OptionalUnnamedAddr
862
///                     'alias|ifunc' IndirectSymbol IndirectSymbolAttr*
863
///
864
/// IndirectSymbol
865
///   ::= TypeAndValue
866
///
867
/// IndirectSymbolAttr
868
///   ::= ',' 'partition' StringConstant
869
///
870
/// Everything through OptionalUnnamedAddr has already been parsed.
871
///
872
bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc,
873
                                   unsigned L, unsigned Visibility,
874
                                   unsigned DLLStorageClass, bool DSOLocal,
875
                                   GlobalVariable::ThreadLocalMode TLM,
876
1.04k
                                   GlobalVariable::UnnamedAddr UnnamedAddr) {
877
1.04k
  bool IsAlias;
878
1.04k
  if (Lex.getKind() == lltok::kw_alias)
879
1.00k
    IsAlias = true;
880
46
  else if (Lex.getKind() == lltok::kw_ifunc)
881
46
    IsAlias = false;
882
46
  else
883
46
    
llvm_unreachable0
("Not an alias or ifunc!");
884
1.04k
  Lex.Lex();
885
1.04k
886
1.04k
  GlobalValue::LinkageTypes Linkage = (GlobalValue::LinkageTypes) L;
887
1.04k
888
1.04k
  if(IsAlias && 
!GlobalAlias::isValidLinkage(Linkage)1.00k
)
889
0
    return Error(NameLoc, "invalid linkage type for alias");
890
1.04k
891
1.04k
  if (!isValidVisibilityForLinkage(Visibility, L))
892
4
    return Error(NameLoc,
893
4
                 "symbol with local linkage must have default visibility");
894
1.04k
895
1.04k
  Type *Ty;
896
1.04k
  LocTy ExplicitTypeLoc = Lex.getLoc();
897
1.04k
  if (ParseType(Ty) ||
898
1.04k
      ParseToken(lltok::comma, "expected comma after alias or ifunc's type"))
899
0
    return true;
900
1.04k
901
1.04k
  Constant *Aliasee;
902
1.04k
  LocTy AliaseeLoc = Lex.getLoc();
903
1.04k
  if (Lex.getKind() != lltok::kw_bitcast &&
904
1.04k
      
Lex.getKind() != lltok::kw_getelementptr888
&&
905
1.04k
      
Lex.getKind() != lltok::kw_addrspacecast760
&&
906
1.04k
      
Lex.getKind() != lltok::kw_inttoptr749
) {
907
742
    if (ParseGlobalTypeAndValue(Aliasee))
908
0
      return true;
909
302
  } else {
910
302
    // The bitcast dest type is not present, it is implied by the dest type.
911
302
    ValID ID;
912
302
    if (ParseValID(ID))
913
1
      return true;
914
301
    if (ID.Kind != ValID::t_Constant)
915
0
      return Error(AliaseeLoc, "invalid aliasee");
916
301
    Aliasee = ID.ConstantVal;
917
301
  }
918
1.04k
919
1.04k
  Type *AliaseeType = Aliasee->getType();
920
1.04k
  auto *PTy = dyn_cast<PointerType>(AliaseeType);
921
1.04k
  if (!PTy)
922
0
    return Error(AliaseeLoc, "An alias or ifunc must have pointer type");
923
1.04k
  unsigned AddrSpace = PTy->getAddressSpace();
924
1.04k
925
1.04k
  if (IsAlias && 
Ty != PTy->getElementType()997
)
926
1
    return Error(
927
1
        ExplicitTypeLoc,
928
1
        "explicit pointee type doesn't match operand's pointee type");
929
1.04k
930
1.04k
  if (!IsAlias && 
!PTy->getElementType()->isFunctionTy()46
)
931
0
    return Error(
932
0
        ExplicitTypeLoc,
933
0
        "explicit pointee type should be a function type");
934
1.04k
935
1.04k
  GlobalValue *GVal = nullptr;
936
1.04k
937
1.04k
  // See if the alias was forward referenced, if so, prepare to replace the
938
1.04k
  // forward reference.
939
1.04k
  if (!Name.empty()) {
940
1.03k
    GVal = M->getNamedValue(Name);
941
1.03k
    if (GVal) {
942
67
      if (!ForwardRefVals.erase(Name))
943
1
        return Error(NameLoc, "redefinition of global '@" + Name + "'");
944
4
    }
945
4
  } else {
946
4
    auto I = ForwardRefValIDs.find(NumberedVals.size());
947
4
    if (I != ForwardRefValIDs.end()) {
948
1
      GVal = I->second.first;
949
1
      ForwardRefValIDs.erase(I);
950
1
    }
951
4
  }
952
1.04k
953
1.04k
  // Okay, create the alias but do not insert it into the module yet.
954
1.04k
  std::unique_ptr<GlobalIndirectSymbol> GA;
955
1.04k
  if (IsAlias)
956
995
    GA.reset(GlobalAlias::create(Ty, AddrSpace,
957
995
                                 (GlobalValue::LinkageTypes)Linkage, Name,
958
995
                                 Aliasee, /*Parent*/ nullptr));
959
46
  else
960
46
    GA.reset(GlobalIFunc::create(Ty, AddrSpace,
961
46
                                 (GlobalValue::LinkageTypes)Linkage, Name,
962
46
                                 Aliasee, /*Parent*/ nullptr));
963
1.04k
  GA->setThreadLocalMode(TLM);
964
1.04k
  GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
965
1.04k
  GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
966
1.04k
  GA->setUnnamedAddr(UnnamedAddr);
967
1.04k
  maybeSetDSOLocal(DSOLocal, *GA);
968
1.04k
969
1.04k
  // At this point we've parsed everything except for the IndirectSymbolAttrs.
970
1.04k
  // Now parse them if there are any.
971
1.04k
  while (Lex.getKind() == lltok::comma) {
972
6
    Lex.Lex();
973
6
974
6
    if (Lex.getKind() == lltok::kw_partition) {
975
6
      Lex.Lex();
976
6
      GA->setPartition(Lex.getStrVal());
977
6
      if (ParseToken(lltok::StringConstant, "expected partition string"))
978
0
        return true;
979
0
    } else {
980
0
      return TokError("unknown alias or ifunc property!");
981
0
    }
982
6
  }
983
1.04k
984
1.04k
  if (Name.empty())
985
4
    NumberedVals.push_back(GA.get());
986
1.04k
987
1.04k
  if (GVal) {
988
67
    // Verify that types agree.
989
67
    if (GVal->getType() != GA->getType())
990
0
      return Error(
991
0
          ExplicitTypeLoc,
992
0
          "forward reference and definition of alias have different types");
993
67
994
67
    // If they agree, just RAUW the old value with the alias and remove the
995
67
    // forward ref info.
996
67
    GVal->replaceAllUsesWith(GA.get());
997
67
    GVal->eraseFromParent();
998
67
  }
999
1.04k
1000
1.04k
  // Insert into the module, we know its name won't collide now.
1001
1.04k
  if (IsAlias)
1002
995
    M->getAliasList().push_back(cast<GlobalAlias>(GA.get()));
1003
46
  else
1004
46
    M->getIFuncList().push_back(cast<GlobalIFunc>(GA.get()));
1005
1.04k
  assert(GA->getName() == Name && "Should not be a name conflict!");
1006
1.04k
1007
1.04k
  // The module owns this now
1008
1.04k
  GA.release();
1009
1.04k
1010
1.04k
  return false;
1011
1.04k
}
1012
1013
/// ParseGlobal
1014
///   ::= GlobalVar '=' OptionalLinkage OptionalPreemptionSpecifier
1015
///       OptionalVisibility OptionalDLLStorageClass
1016
///       OptionalThreadLocal OptionalUnnamedAddr OptionalAddrSpace
1017
///       OptionalExternallyInitialized GlobalType Type Const OptionalAttrs
1018
///   ::= OptionalLinkage OptionalPreemptionSpecifier OptionalVisibility
1019
///       OptionalDLLStorageClass OptionalThreadLocal OptionalUnnamedAddr
1020
///       OptionalAddrSpace OptionalExternallyInitialized GlobalType Type
1021
///       Const OptionalAttrs
1022
///
1023
/// Everything up to and including OptionalUnnamedAddr has been parsed
1024
/// already.
1025
///
1026
bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
1027
                           unsigned Linkage, bool HasLinkage,
1028
                           unsigned Visibility, unsigned DLLStorageClass,
1029
                           bool DSOLocal, GlobalVariable::ThreadLocalMode TLM,
1030
30.5k
                           GlobalVariable::UnnamedAddr UnnamedAddr) {
1031
30.5k
  if (!isValidVisibilityForLinkage(Visibility, Linkage))
1032
4
    return Error(NameLoc,
1033
4
                 "symbol with local linkage must have default visibility");
1034
30.5k
1035
30.5k
  unsigned AddrSpace;
1036
30.5k
  bool IsConstant, IsExternallyInitialized;
1037
30.5k
  LocTy IsExternallyInitializedLoc;
1038
30.5k
  LocTy TyLoc;
1039
30.5k
1040
30.5k
  Type *Ty = nullptr;
1041
30.5k
  if (ParseOptionalAddrSpace(AddrSpace) ||
1042
30.5k
      ParseOptionalToken(lltok::kw_externally_initialized,
1043
30.5k
                         IsExternallyInitialized,
1044
30.5k
                         &IsExternallyInitializedLoc) ||
1045
30.5k
      ParseGlobalType(IsConstant) ||
1046
30.5k
      ParseType(Ty, TyLoc))
1047
2
    return true;
1048
30.5k
1049
30.5k
  // If the linkage is specified and is external, then no initializer is
1050
30.5k
  // present.
1051
30.5k
  Constant *Init = nullptr;
1052
30.5k
  if (!HasLinkage ||
1053
30.5k
      !GlobalValue::isValidDeclarationLinkage(
1054
23.4k
          (GlobalValue::LinkageTypes)Linkage)) {
1055
23.4k
    if (ParseGlobalValue(Ty, Init))
1056
12
      return true;
1057
30.5k
  }
1058
30.5k
1059
30.5k
  if (Ty->isFunctionTy() || !PointerType::isValidElementType(Ty))
1060
2
    return Error(TyLoc, "invalid type for global variable");
1061
30.5k
1062
30.5k
  GlobalValue *GVal = nullptr;
1063
30.5k
1064
30.5k
  // See if the global was forward referenced, if so, use the global.
1065
30.5k
  if (!Name.empty()) {
1066
29.8k
    GVal = M->getNamedValue(Name);
1067
29.8k
    if (GVal) {
1068
527
      if (!ForwardRefVals.erase(Name))
1069
1
        return Error(NameLoc, "redefinition of global '@" + Name + "'");
1070
685
    }
1071
685
  } else {
1072
685
    auto I = ForwardRefValIDs.find(NumberedVals.size());
1073
685
    if (I != ForwardRefValIDs.end()) {
1074
22
      GVal = I->second.first;
1075
22
      ForwardRefValIDs.erase(I);
1076
22
    }
1077
685
  }
1078
30.5k
1079
30.5k
  GlobalVariable *GV;
1080
30.5k
  if (!GVal) {
1081
29.9k
    GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, nullptr,
1082
29.9k
                            Name, nullptr, GlobalVariable::NotThreadLocal,
1083
29.9k
                            AddrSpace);
1084
29.9k
  } else {
1085
548
    if (GVal->getValueType() != Ty)
1086
1
      return Error(TyLoc,
1087
1
            "forward reference and definition of global have different types");
1088
547
1089
547
    GV = cast<GlobalVariable>(GVal);
1090
547
1091
547
    // Move the forward-reference to the correct spot in the module.
1092
547
    M->getGlobalList().splice(M->global_end(), M->getGlobalList(), GV);
1093
547
  }
1094
30.5k
1095
30.5k
  
if (30.5k
Name.empty()30.5k
)
1096
685
    NumberedVals.push_back(GV);
1097
30.5k
1098
30.5k
  // Set the parsed properties on the global.
1099
30.5k
  if (Init)
1100
23.4k
    GV->setInitializer(Init);
1101
30.5k
  GV->setConstant(IsConstant);
1102
30.5k
  GV->setLinkage((GlobalValue::LinkageTypes)Linkage);
1103
30.5k
  maybeSetDSOLocal(DSOLocal, *GV);
1104
30.5k
  GV->setVisibility((GlobalValue::VisibilityTypes)Visibility);
1105
30.5k
  GV->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
1106
30.5k
  GV->setExternallyInitialized(IsExternallyInitialized);
1107
30.5k
  GV->setThreadLocalMode(TLM);
1108
30.5k
  GV->setUnnamedAddr(UnnamedAddr);
1109
30.5k
1110
30.5k
  // Parse attributes on the global.
1111
50.5k
  while (Lex.getKind() == lltok::comma) {
1112
20.0k
    Lex.Lex();
1113
20.0k
1114
20.0k
    if (Lex.getKind() == lltok::kw_section) {
1115
632
      Lex.Lex();
1116
632
      GV->setSection(Lex.getStrVal());
1117
632
      if (ParseToken(lltok::StringConstant, "expected global section string"))
1118
0
        return true;
1119
19.4k
    } else if (Lex.getKind() == lltok::kw_partition) {
1120
3
      Lex.Lex();
1121
3
      GV->setPartition(Lex.getStrVal());
1122
3
      if (ParseToken(lltok::StringConstant, "expected partition string"))
1123
0
        return true;
1124
19.3k
    } else if (Lex.getKind() == lltok::kw_align) {
1125
17.1k
      unsigned Alignment;
1126
17.1k
      if (ParseOptionalAlignment(Alignment)) 
return true0
;
1127
17.1k
      GV->setAlignment(Alignment);
1128
17.1k
    } else 
if (2.24k
Lex.getKind() == lltok::MetadataVar2.24k
) {
1129
1.73k
      if (ParseGlobalObjectMetadataAttachment(*GV))
1130
0
        return true;
1131
502
    } else {
1132
502
      Comdat *C;
1133
502
      if (parseOptionalComdat(Name, C))
1134
0
        return true;
1135
502
      if (C)
1136
502
        GV->setComdat(C);
1137
0
      else
1138
0
        return TokError("unknown global variable property!");
1139
502
    }
1140
20.0k
  }
1141
30.5k
1142
30.5k
  AttrBuilder Attrs;
1143
30.5k
  LocTy BuiltinLoc;
1144
30.5k
  std::vector<unsigned> FwdRefAttrGrps;
1145
30.5k
  if (ParseFnAttributeValuePairs(Attrs, FwdRefAttrGrps, false, BuiltinLoc))
1146
0
    return true;
1147
30.5k
  if (Attrs.hasAttributes() || 
!FwdRefAttrGrps.empty()30.5k
) {
1148
38
    GV->setAttributes(AttributeSet::get(Context, Attrs));
1149
38
    ForwardRefAttrGroups[GV] = FwdRefAttrGrps;
1150
38
  }
1151
30.5k
1152
30.5k
  return false;
1153
30.5k
}
1154
1155
/// ParseUnnamedAttrGrp
1156
///   ::= 'attributes' AttrGrpID '=' '{' AttrValPair+ '}'
1157
10.8k
bool LLParser::ParseUnnamedAttrGrp() {
1158
10.8k
  assert(Lex.getKind() == lltok::kw_attributes);
1159
10.8k
  LocTy AttrGrpLoc = Lex.getLoc();
1160
10.8k
  Lex.Lex();
1161
10.8k
1162
10.8k
  if (Lex.getKind() != lltok::AttrGrpID)
1163
1
    return TokError("expected attribute group id");
1164
10.8k
1165
10.8k
  unsigned VarID = Lex.getUIntVal();
1166
10.8k
  std::vector<unsigned> unused;
1167
10.8k
  LocTy BuiltinLoc;
1168
10.8k
  Lex.Lex();
1169
10.8k
1170
10.8k
  if (ParseToken(lltok::equal, "expected '=' here") ||
1171
10.8k
      ParseToken(lltok::lbrace, "expected '{' here") ||
1172
10.8k
      ParseFnAttributeValuePairs(NumberedAttrBuilders[VarID], unused, true,
1173
10.8k
                                 BuiltinLoc) ||
1174
10.8k
      ParseToken(lltok::rbrace, "expected end of attribute group"))
1175
0
    return true;
1176
10.8k
1177
10.8k
  if (!NumberedAttrBuilders[VarID].hasAttributes())
1178
0
    return Error(AttrGrpLoc, "attribute group has no attributes");
1179
10.8k
1180
10.8k
  return false;
1181
10.8k
}
1182
1183
/// ParseFnAttributeValuePairs
1184
///   ::= <attr> | <attr> '=' <value>
1185
bool LLParser::ParseFnAttributeValuePairs(AttrBuilder &B,
1186
                                          std::vector<unsigned> &FwdRefAttrGrps,
1187
611k
                                          bool inAttrGrp, LocTy &BuiltinLoc) {
1188
611k
  bool HaveError = false;
1189
611k
1190
611k
  B.clear();
1191
611k
1192
838k
  while (true) {
1193
838k
    lltok::Kind Token = Lex.getKind();
1194
838k
    if (Token == lltok::kw_builtin)
1195
62
      BuiltinLoc = Lex.getLoc();
1196
838k
    switch (Token) {
1197
838k
    default:
1198
600k
      if (!inAttrGrp) return HaveError;
1199
0
      return Error(Lex.getLoc(), "unterminated attribute group");
1200
10.8k
    case lltok::rbrace:
1201
10.8k
      // Finished.
1202
10.8k
      return false;
1203
0
1204
66.3k
    case lltok::AttrGrpID: {
1205
66.3k
      // Allow a function to reference an attribute group:
1206
66.3k
      //
1207
66.3k
      //   define void @foo() #1 { ... }
1208
66.3k
      if (inAttrGrp)
1209
0
        HaveError |=
1210
0
          Error(Lex.getLoc(),
1211
0
              "cannot have an attribute group reference in an attribute group");
1212
66.3k
1213
66.3k
      unsigned AttrGrpNum = Lex.getUIntVal();
1214
66.3k
      if (inAttrGrp) 
break0
;
1215
66.3k
1216
66.3k
      // Save the reference to the attribute group. We'll fill it in later.
1217
66.3k
      FwdRefAttrGrps.push_back(AttrGrpNum);
1218
66.3k
      break;
1219
66.3k
    }
1220
66.3k
    // Target-dependent attributes:
1221
66.3k
    case lltok::StringConstant: {
1222
21.9k
      if (ParseStringAttribute(B))
1223
0
        return true;
1224
21.9k
      continue;
1225
21.9k
    }
1226
21.9k
1227
21.9k
    // Target-independent attributes:
1228
21.9k
    case lltok::kw_align: {
1229
699
      // As a hack, we allow function alignment to be initially parsed as an
1230
699
      // attribute on a function declaration/definition or added to an attribute
1231
699
      // group and later moved to the alignment field.
1232
699
      unsigned Alignment;
1233
699
      if (inAttrGrp) {
1234
1
        Lex.Lex();
1235
1
        if (ParseToken(lltok::equal, "expected '=' here") ||
1236
1
            ParseUInt32(Alignment))
1237
0
          return true;
1238
698
      } else {
1239
698
        if (ParseOptionalAlignment(Alignment))
1240
0
          return true;
1241
699
      }
1242
699
      B.addAlignmentAttr(Alignment);
1243
699
      continue;
1244
699
    }
1245
699
    case lltok::kw_alignstack: {
1246
50
      unsigned Alignment;
1247
50
      if (inAttrGrp) {
1248
16
        Lex.Lex();
1249
16
        if (ParseToken(lltok::equal, "expected '=' here") ||
1250
16
            ParseUInt32(Alignment))
1251
0
          return true;
1252
34
      } else {
1253
34
        if (ParseOptionalStackAlignment(Alignment))
1254
0
          return true;
1255
50
      }
1256
50
      B.addStackAlignmentAttr(Alignment);
1257
50
      continue;
1258
50
    }
1259
50
    case lltok::kw_allocsize: {
1260
25
      unsigned ElemSizeArg;
1261
25
      Optional<unsigned> NumElemsArg;
1262
25
      // inAttrGrp doesn't matter; we only support allocsize(a[, b])
1263
25
      if (parseAllocSizeArguments(ElemSizeArg, NumElemsArg))
1264
1
        return true;
1265
24
      B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1266
24
      continue;
1267
24
    }
1268
268
    case lltok::kw_alwaysinline: B.addAttribute(Attribute::AlwaysInline); break;
1269
434
    case lltok::kw_argmemonly: B.addAttribute(Attribute::ArgMemOnly); break;
1270
62
    case lltok::kw_builtin: B.addAttribute(Attribute::Builtin); break;
1271
69
    case lltok::kw_cold: B.addAttribute(Attribute::Cold); break;
1272
310
    case lltok::kw_convergent: B.addAttribute(Attribute::Convergent); break;
1273
81
    case lltok::kw_inaccessiblememonly:
1274
81
      B.addAttribute(Attribute::InaccessibleMemOnly); break;
1275
24
    case lltok::kw_inaccessiblemem_or_argmemonly:
1276
19
      B.addAttribute(Attribute::InaccessibleMemOrArgMemOnly); break;
1277
183
    case lltok::kw_inlinehint: B.addAttribute(Attribute::InlineHint); break;
1278
24
    
case lltok::kw_jumptable: B.addAttribute(Attribute::JumpTable); break9
;
1279
814
    case lltok::kw_minsize: B.addAttribute(Attribute::MinSize); break;
1280
29
    case lltok::kw_naked: B.addAttribute(Attribute::Naked); break;
1281
140
    case lltok::kw_nobuiltin: B.addAttribute(Attribute::NoBuiltin); break;
1282
66
    case lltok::kw_noduplicate: B.addAttribute(Attribute::NoDuplicate); break;
1283
24
    
case lltok::kw_nofree: B.addAttribute(Attribute::NoFree); break10
;
1284
57
    case lltok::kw_noimplicitfloat:
1285
57
      B.addAttribute(Attribute::NoImplicitFloat); break;
1286
1.43k
    case lltok::kw_noinline: B.addAttribute(Attribute::NoInline); break;
1287
44
    case lltok::kw_nonlazybind: B.addAttribute(Attribute::NonLazyBind); break;
1288
219
    case lltok::kw_noredzone: B.addAttribute(Attribute::NoRedZone); break;
1289
600
    case lltok::kw_noreturn: B.addAttribute(Attribute::NoReturn); break;
1290
24
    
case lltok::kw_nosync: B.addAttribute(Attribute::NoSync); break8
;
1291
24
    
case lltok::kw_nocf_check: B.addAttribute(Attribute::NoCfCheck); break2
;
1292
445
    case lltok::kw_norecurse: B.addAttribute(Attribute::NoRecurse); break;
1293
95.1k
    case lltok::kw_nounwind: B.addAttribute(Attribute::NoUnwind); break;
1294
24
    case lltok::kw_optforfuzzing:
1295
1
      B.addAttribute(Attribute::OptForFuzzing); break;
1296
235
    case lltok::kw_optnone: B.addAttribute(Attribute::OptimizeNone); break;
1297
1.96k
    case lltok::kw_optsize: B.addAttribute(Attribute::OptimizeForSize); break;
1298
19.2k
    case lltok::kw_readnone: B.addAttribute(Attribute::ReadNone); break;
1299
2.42k
    case lltok::kw_readonly: B.addAttribute(Attribute::ReadOnly); break;
1300
91
    case lltok::kw_returns_twice:
1301
91
      B.addAttribute(Attribute::ReturnsTwice); break;
1302
509
    case lltok::kw_speculatable: B.addAttribute(Attribute::Speculatable); break;
1303
5.94k
    case lltok::kw_ssp: B.addAttribute(Attribute::StackProtect); break;
1304
78
    case lltok::kw_sspreq: B.addAttribute(Attribute::StackProtectReq); break;
1305
90
    case lltok::kw_sspstrong:
1306
90
      B.addAttribute(Attribute::StackProtectStrong); break;
1307
199
    case lltok::kw_safestack: B.addAttribute(Attribute::SafeStack); break;
1308
24
    case lltok::kw_shadowcallstack:
1309
11
      B.addAttribute(Attribute::ShadowCallStack); break;
1310
382
    case lltok::kw_sanitize_address:
1311
382
      B.addAttribute(Attribute::SanitizeAddress); break;
1312
210
    case lltok::kw_sanitize_hwaddress:
1313
210
      B.addAttribute(Attribute::SanitizeHWAddress); break;
1314
24
    case lltok::kw_sanitize_memtag:
1315
19
      B.addAttribute(Attribute::SanitizeMemTag); break;
1316
73
    case lltok::kw_sanitize_thread:
1317
73
      B.addAttribute(Attribute::SanitizeThread); break;
1318
708
    case lltok::kw_sanitize_memory:
1319
708
      B.addAttribute(Attribute::SanitizeMemory); break;
1320
59
    case lltok::kw_speculative_load_hardening:
1321
59
      B.addAttribute(Attribute::SpeculativeLoadHardening);
1322
59
      break;
1323
24
    
case lltok::kw_strictfp: B.addAttribute(Attribute::StrictFP); break6
;
1324
5.37k
    case lltok::kw_uwtable: B.addAttribute(Attribute::UWTable); break;
1325
24
    
case lltok::kw_willreturn: B.addAttribute(Attribute::WillReturn); break11
;
1326
47
    case lltok::kw_writeonly: B.addAttribute(Attribute::WriteOnly); break;
1327
24
1328
24
    // Error handling.
1329
24
    case lltok::kw_inreg:
1330
0
    case lltok::kw_signext:
1331
0
    case lltok::kw_zeroext:
1332
0
      HaveError |=
1333
0
        Error(Lex.getLoc(),
1334
0
              "invalid use of attribute on a function");
1335
0
      break;
1336
1
    case lltok::kw_byval:
1337
1
    case lltok::kw_dereferenceable:
1338
1
    case lltok::kw_dereferenceable_or_null:
1339
1
    case lltok::kw_inalloca:
1340
1
    case lltok::kw_nest:
1341
1
    case lltok::kw_noalias:
1342
1
    case lltok::kw_nocapture:
1343
1
    case lltok::kw_nonnull:
1344
1
    case lltok::kw_returned:
1345
1
    case lltok::kw_sret:
1346
1
    case lltok::kw_swifterror:
1347
1
    case lltok::kw_swiftself:
1348
1
    case lltok::kw_immarg:
1349
1
      HaveError |=
1350
1
        Error(Lex.getLoc(),
1351
1
              "invalid use of parameter-only attribute on a function");
1352
1
      break;
1353
204k
    }
1354
204k
1355
204k
    Lex.Lex();
1356
204k
  }
1357
611k
}
1358
1359
//===----------------------------------------------------------------------===//
1360
// GlobalValue Reference/Resolution Routines.
1361
//===----------------------------------------------------------------------===//
1362
1363
static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy,
1364
51.2k
                                              const std::string &Name) {
1365
51.2k
  if (auto *FT = dyn_cast<FunctionType>(PTy->getElementType()))
1366
50.6k
    return Function::Create(FT, GlobalValue::ExternalWeakLinkage,
1367
50.6k
                            PTy->getAddressSpace(), Name, M);
1368
581
  else
1369
581
    return new GlobalVariable(*M, PTy->getElementType(), false,
1370
581
                              GlobalValue::ExternalWeakLinkage, nullptr, Name,
1371
581
                              nullptr, GlobalVariable::NotThreadLocal,
1372
581
                              PTy->getAddressSpace());
1373
51.2k
}
1374
1375
Value *LLParser::checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
1376
2.29M
                                        Value *Val, bool IsCall) {
1377
2.29M
  if (Val->getType() == Ty)
1378
2.29M
    return Val;
1379
15
  // For calls we also accept variables in the program address space.
1380
15
  Type *SuggestedTy = Ty;
1381
15
  if (IsCall && 
isa<PointerType>(Ty)8
) {
1382
8
    Type *TyInProgAS = cast<PointerType>(Ty)->getElementType()->getPointerTo(
1383
8
        M->getDataLayout().getProgramAddressSpace());
1384
8
    SuggestedTy = TyInProgAS;
1385
8
    if (Val->getType() == TyInProgAS)
1386
0
      return Val;
1387
15
  }
1388
15
  if (Ty->isLabelTy())
1389
0
    Error(Loc, "'" + Name + "' is not a basic block");
1390
15
  else
1391
15
    Error(Loc, "'" + Name + "' defined with type '" +
1392
15
                   getTypeString(Val->getType()) + "' but expected '" +
1393
15
                   getTypeString(SuggestedTy) + "'");
1394
15
  return nullptr;
1395
15
}
1396
1397
/// GetGlobalVal - Get a value with the specified name or ID, creating a
1398
/// forward reference record if needed.  This can return null if the value
1399
/// exists but does not have the right type.
1400
GlobalValue *LLParser::GetGlobalVal(const std::string &Name, Type *Ty,
1401
297k
                                    LocTy Loc, bool IsCall) {
1402
297k
  PointerType *PTy = dyn_cast<PointerType>(Ty);
1403
297k
  if (!PTy) {
1404
0
    Error(Loc, "global variable reference must have pointer type");
1405
0
    return nullptr;
1406
0
  }
1407
297k
1408
297k
  // Look this name up in the normal function symbol table.
1409
297k
  GlobalValue *Val =
1410
297k
    cast_or_null<GlobalValue>(M->getValueSymbolTable().lookup(Name));
1411
297k
1412
297k
  // If this is a forward reference for the value, see if we already created a
1413
297k
  // forward ref record.
1414
297k
  if (!Val) {
1415
51.1k
    auto I = ForwardRefVals.find(Name);
1416
51.1k
    if (I != ForwardRefVals.end())
1417
0
      Val = I->second.first;
1418
51.1k
  }
1419
297k
1420
297k
  // If we have the value in the symbol table or fwd-ref table, return it.
1421
297k
  if (Val)
1422
246k
    return cast_or_null<GlobalValue>(
1423
246k
        checkValidVariableType(Loc, "@" + Name, Ty, Val, IsCall));
1424
51.1k
1425
51.1k
  // Otherwise, create a new forward reference for this value and remember it.
1426
51.1k
  GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, Name);
1427
51.1k
  ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
1428
51.1k
  return FwdVal;
1429
51.1k
}
1430
1431
GlobalValue *LLParser::GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc,
1432
665
                                    bool IsCall) {
1433
665
  PointerType *PTy = dyn_cast<PointerType>(Ty);
1434
665
  if (!PTy) {
1435
0
    Error(Loc, "global variable reference must have pointer type");
1436
0
    return nullptr;
1437
0
  }
1438
665
1439
665
  GlobalValue *Val = ID < NumberedVals.size() ? 
NumberedVals[ID]613
:
nullptr52
;
1440
665
1441
665
  // If this is a forward reference for the value, see if we already created a
1442
665
  // forward ref record.
1443
665
  if (!Val) {
1444
52
    auto I = ForwardRefValIDs.find(ID);
1445
52
    if (I != ForwardRefValIDs.end())
1446
8
      Val = I->second.first;
1447
52
  }
1448
665
1449
665
  // If we have the value in the symbol table or fwd-ref table, return it.
1450
665
  if (Val)
1451
621
    return cast_or_null<GlobalValue>(
1452
621
        checkValidVariableType(Loc, "@" + Twine(ID), Ty, Val, IsCall));
1453
44
1454
44
  // Otherwise, create a new forward reference for this value and remember it.
1455
44
  GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, "");
1456
44
  ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
1457
44
  return FwdVal;
1458
44
}
1459
1460
//===----------------------------------------------------------------------===//
1461
// Comdat Reference/Resolution Routines.
1462
//===----------------------------------------------------------------------===//
1463
1464
906
Comdat *LLParser::getComdat(const std::string &Name, LocTy Loc) {
1465
906
  // Look this name up in the comdat symbol table.
1466
906
  Module::ComdatSymTabType &ComdatSymTab = M->getComdatSymbolTable();
1467
906
  Module::ComdatSymTabType::iterator I = ComdatSymTab.find(Name);
1468
906
  if (I != ComdatSymTab.end())
1469
904
    return &I->second;
1470
2
1471
2
  // Otherwise, create a new forward reference for this value and remember it.
1472
2
  Comdat *C = M->getOrInsertComdat(Name);
1473
2
  ForwardRefComdats[Name] = Loc;
1474
2
  return C;
1475
2
}
1476
1477
//===----------------------------------------------------------------------===//
1478
// Helper Routines.
1479
//===----------------------------------------------------------------------===//
1480
1481
/// ParseToken - If the current token has the specified kind, eat it and return
1482
/// success.  Otherwise, emit the specified error and return failure.
1483
8.10M
bool LLParser::ParseToken(lltok::Kind T, const char *ErrMsg) {
1484
8.10M
  if (Lex.getKind() != T)
1485
6
    return TokError(ErrMsg);
1486
8.10M
  Lex.Lex();
1487
8.10M
  return false;
1488
8.10M
}
1489
1490
/// ParseStringConstant
1491
///   ::= StringConstant
1492
105k
bool LLParser::ParseStringConstant(std::string &Result) {
1493
105k
  if (Lex.getKind() != lltok::StringConstant)
1494
0
    return TokError("expected string constant");
1495
105k
  Result = Lex.getStrVal();
1496
105k
  Lex.Lex();
1497
105k
  return false;
1498
105k
}
1499
1500
/// ParseUInt32
1501
///   ::= uint32
1502
669k
bool LLParser::ParseUInt32(uint32_t &Val) {
1503
669k
  if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
1504
0
    return TokError("expected integer");
1505
669k
  uint64_t Val64 = Lex.getAPSIntVal().getLimitedValue(0xFFFFFFFFULL+1);
1506
669k
  if (Val64 != unsigned(Val64))
1507
0
    return TokError("expected 32-bit integer (too large)");
1508
669k
  Val = Val64;
1509
669k
  Lex.Lex();
1510
669k
  return false;
1511
669k
}
1512
1513
/// ParseUInt64
1514
///   ::= uint64
1515
895
bool LLParser::ParseUInt64(uint64_t &Val) {
1516
895
  if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
1517
0
    return TokError("expected integer");
1518
895
  Val = Lex.getAPSIntVal().getLimitedValue();
1519
895
  Lex.Lex();
1520
895
  return false;
1521
895
}
1522
1523
/// ParseTLSModel
1524
///   := 'localdynamic'
1525
///   := 'initialexec'
1526
///   := 'localexec'
1527
187
bool LLParser::ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM) {
1528
187
  switch (Lex.getKind()) {
1529
187
    default:
1530
0
      return TokError("expected localdynamic, initialexec or localexec");
1531
187
    case lltok::kw_localdynamic:
1532
59
      TLM = GlobalVariable::LocalDynamicTLSModel;
1533
59
      break;
1534
187
    case lltok::kw_initialexec:
1535
65
      TLM = GlobalVariable::InitialExecTLSModel;
1536
65
      break;
1537
187
    case lltok::kw_localexec:
1538
63
      TLM = GlobalVariable::LocalExecTLSModel;
1539
63
      break;
1540
187
  }
1541
187
1542
187
  Lex.Lex();
1543
187
  return false;
1544
187
}
1545
1546
/// ParseOptionalThreadLocal
1547
///   := /*empty*/
1548
///   := 'thread_local'
1549
///   := 'thread_local' '(' tlsmodel ')'
1550
31.5k
bool LLParser::ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM) {
1551
31.5k
  TLM = GlobalVariable::NotThreadLocal;
1552
31.5k
  if (!EatIfPresent(lltok::kw_thread_local))
1553
30.6k
    return false;
1554
946
1555
946
  TLM = GlobalVariable::GeneralDynamicTLSModel;
1556
946
  if (Lex.getKind() == lltok::lparen) {
1557
187
    Lex.Lex();
1558
187
    return ParseTLSModel(TLM) ||
1559
187
      ParseToken(lltok::rparen, "expected ')' after thread local model");
1560
187
  }
1561
759
  return false;
1562
759
}
1563
1564
/// ParseOptionalAddrSpace
1565
///   := /*empty*/
1566
///   := 'addrspace' '(' uint32 ')'
1567
716k
bool LLParser::ParseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS) {
1568
716k
  AddrSpace = DefaultAS;
1569
716k
  if (!EatIfPresent(lltok::kw_addrspace))
1570
599k
    return false;
1571
116k
  return ParseToken(lltok::lparen, "expected '(' in address space") ||
1572
116k
         ParseUInt32(AddrSpace) ||
1573
116k
         ParseToken(lltok::rparen, "expected ')' in address space");
1574
116k
}
1575
1576
/// ParseStringAttribute
1577
///   := StringConstant
1578
///   := StringConstant '=' StringConstant
1579
22.0k
bool LLParser::ParseStringAttribute(AttrBuilder &B) {
1580
22.0k
  std::string Attr = Lex.getStrVal();
1581
22.0k
  Lex.Lex();
1582
22.0k
  std::string Val;
1583
22.0k
  if (EatIfPresent(lltok::equal) && 
ParseStringConstant(Val)20.7k
)
1584
0
    return true;
1585
22.0k
  B.addAttribute(Attr, Val);
1586
22.0k
  return false;
1587
22.0k
}
1588
1589
/// ParseOptionalParamAttrs - Parse a potentially empty list of parameter attributes.
1590
1.04M
bool LLParser::ParseOptionalParamAttrs(AttrBuilder &B) {
1591
1.04M
  bool HaveError = false;
1592
1.04M
1593
1.04M
  B.clear();
1594
1.04M
1595
1.10M
  while (true) {
1596
1.10M
    lltok::Kind Token = Lex.getKind();
1597
1.10M
    switch (Token) {
1598
1.10M
    default:  // End of attributes.
1599
1.04M
      return HaveError;
1600
1.10M
    case lltok::StringConstant: {
1601
14
      if (ParseStringAttribute(B))
1602
0
        return true;
1603
14
      continue;
1604
14
    }
1605
6.07k
    case lltok::kw_align: {
1606
6.07k
      unsigned Alignment;
1607
6.07k
      if (ParseOptionalAlignment(Alignment))
1608
1
        return true;
1609
6.07k
      B.addAlignmentAttr(Alignment);
1610
6.07k
      continue;
1611
6.07k
    }
1612
6.07k
    case lltok::kw_byval: {
1613
1.77k
      Type *Ty;
1614
1.77k
      if (ParseByValWithOptionalType(Ty))
1615
1
        return true;
1616
1.77k
      B.addByValAttr(Ty);
1617
1.77k
      continue;
1618
1.77k
    }
1619
1.77k
    case lltok::kw_dereferenceable: {
1620
615
      uint64_t Bytes;
1621
615
      if (ParseOptionalDerefAttrBytes(lltok::kw_dereferenceable, Bytes))
1622
0
        return true;
1623
615
      B.addDereferenceableAttr(Bytes);
1624
615
      continue;
1625
615
    }
1626
615
    case lltok::kw_dereferenceable_or_null: {
1627
54
      uint64_t Bytes;
1628
54
      if (ParseOptionalDerefAttrBytes(lltok::kw_dereferenceable_or_null, Bytes))
1629
0
        return true;
1630
54
      B.addDereferenceableOrNullAttr(Bytes);
1631
54
      continue;
1632
54
    }
1633
139
    case lltok::kw_inalloca:        B.addAttribute(Attribute::InAlloca); break;
1634
5.82k
    case lltok::kw_inreg:           B.addAttribute(Attribute::InReg); break;
1635
95
    case lltok::kw_nest:            B.addAttribute(Attribute::Nest); break;
1636
5.51k
    case lltok::kw_noalias:         B.addAttribute(Attribute::NoAlias); break;
1637
17.4k
    case lltok::kw_nocapture:       B.addAttribute(Attribute::NoCapture); break;
1638
2.04k
    case lltok::kw_nonnull:         B.addAttribute(Attribute::NonNull); break;
1639
342
    case lltok::kw_readnone:        B.addAttribute(Attribute::ReadNone); break;
1640
5.56k
    case lltok::kw_readonly:        B.addAttribute(Attribute::ReadOnly); break;
1641
333
    case lltok::kw_returned:        B.addAttribute(Attribute::Returned); break;
1642
10.1k
    case lltok::kw_signext:         B.addAttribute(Attribute::SExt); break;
1643
1.45k
    case lltok::kw_sret:            B.addAttribute(Attribute::StructRet); break;
1644
363
    case lltok::kw_swifterror:      B.addAttribute(Attribute::SwiftError); break;
1645
210
    case lltok::kw_swiftself:       B.addAttribute(Attribute::SwiftSelf); break;
1646
322
    case lltok::kw_writeonly:       B.addAttribute(Attribute::WriteOnly); break;
1647
7.77k
    case lltok::kw_zeroext:         B.addAttribute(Attribute::ZExt); break;
1648
413
    case lltok::kw_immarg:          B.addAttribute(Attribute::ImmArg); break;
1649
54
1650
54
    case lltok::kw_alignstack:
1651
1
    case lltok::kw_alwaysinline:
1652
1
    case lltok::kw_argmemonly:
1653
1
    case lltok::kw_builtin:
1654
1
    case lltok::kw_inlinehint:
1655
1
    case lltok::kw_jumptable:
1656
1
    case lltok::kw_minsize:
1657
1
    case lltok::kw_naked:
1658
1
    case lltok::kw_nobuiltin:
1659
1
    case lltok::kw_noduplicate:
1660
1
    case lltok::kw_noimplicitfloat:
1661
1
    case lltok::kw_noinline:
1662
1
    case lltok::kw_nonlazybind:
1663
1
    case lltok::kw_noredzone:
1664
1
    case lltok::kw_noreturn:
1665
1
    case lltok::kw_nocf_check:
1666
1
    case lltok::kw_nounwind:
1667
1
    case lltok::kw_optforfuzzing:
1668
1
    case lltok::kw_optnone:
1669
1
    case lltok::kw_optsize:
1670
1
    case lltok::kw_returns_twice:
1671
1
    case lltok::kw_sanitize_address:
1672
1
    case lltok::kw_sanitize_hwaddress:
1673
1
    case lltok::kw_sanitize_memtag:
1674
1
    case lltok::kw_sanitize_memory:
1675
1
    case lltok::kw_sanitize_thread:
1676
1
    case lltok::kw_speculative_load_hardening:
1677
1
    case lltok::kw_ssp:
1678
1
    case lltok::kw_sspreq:
1679
1
    case lltok::kw_sspstrong:
1680
1
    case lltok::kw_safestack:
1681
1
    case lltok::kw_shadowcallstack:
1682
1
    case lltok::kw_strictfp:
1683
1
    case lltok::kw_uwtable:
1684
1
      HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
1685
1
      break;
1686
57.9k
    }
1687
57.9k
1688
57.9k
    Lex.Lex();
1689
57.9k
  }
1690
1.04M
}
1691
1692
/// ParseOptionalReturnAttrs - Parse a potentially empty list of return attributes.
1693
569k
bool LLParser::ParseOptionalReturnAttrs(AttrBuilder &B) {
1694
569k
  bool HaveError = false;
1695
569k
1696
569k
  B.clear();
1697
569k
1698
580k
  while (true) {
1699
580k
    lltok::Kind Token = Lex.getKind();
1700
580k
    switch (Token) {
1701
580k
    default:  // End of attributes.
1702
569k
      return HaveError;
1703
580k
    case lltok::StringConstant: {
1704
16
      if (ParseStringAttribute(B))
1705
0
        return true;
1706
16
      continue;
1707
16
    }
1708
80
    case lltok::kw_dereferenceable: {
1709
80
      uint64_t Bytes;
1710
80
      if (ParseOptionalDerefAttrBytes(lltok::kw_dereferenceable, Bytes))
1711
0
        return true;
1712
80
      B.addDereferenceableAttr(Bytes);
1713
80
      continue;
1714
80
    }
1715
80
    case lltok::kw_dereferenceable_or_null: {
1716
14
      uint64_t Bytes;
1717
14
      if (ParseOptionalDerefAttrBytes(lltok::kw_dereferenceable_or_null, Bytes))
1718
0
        return true;
1719
14
      B.addDereferenceableOrNullAttr(Bytes);
1720
14
      continue;
1721
14
    }
1722
14
    case lltok::kw_align: {
1723
5
      unsigned Alignment;
1724
5
      if (ParseOptionalAlignment(Alignment))
1725
0
        return true;
1726
5
      B.addAlignmentAttr(Alignment);
1727
5
      continue;
1728
5
    }
1729
88
    case lltok::kw_inreg:           B.addAttribute(Attribute::InReg); break;
1730
577
    case lltok::kw_noalias:         B.addAttribute(Attribute::NoAlias); break;
1731
80
    case lltok::kw_nonnull:         B.addAttribute(Attribute::NonNull); break;
1732
5.23k
    case lltok::kw_signext:         B.addAttribute(Attribute::SExt); break;
1733
4.63k
    case lltok::kw_zeroext:         B.addAttribute(Attribute::ZExt); break;
1734
5
1735
5
    // Error handling.
1736
5
    case lltok::kw_byval:
1737
2
    case lltok::kw_inalloca:
1738
2
    case lltok::kw_nest:
1739
2
    case lltok::kw_nocapture:
1740
2
    case lltok::kw_returned:
1741
2
    case lltok::kw_sret:
1742
2
    case lltok::kw_swifterror:
1743
2
    case lltok::kw_swiftself:
1744
2
    case lltok::kw_immarg:
1745
2
      HaveError |= Error(Lex.getLoc(), "invalid use of parameter-only attribute");
1746
2
      break;
1747
2
1748
2
    case lltok::kw_alignstack:
1749
1
    case lltok::kw_alwaysinline:
1750
1
    case lltok::kw_argmemonly:
1751
1
    case lltok::kw_builtin:
1752
1
    case lltok::kw_cold:
1753
1
    case lltok::kw_inlinehint:
1754
1
    case lltok::kw_jumptable:
1755
1
    case lltok::kw_minsize:
1756
1
    case lltok::kw_naked:
1757
1
    case lltok::kw_nobuiltin:
1758
1
    case lltok::kw_noduplicate:
1759
1
    case lltok::kw_noimplicitfloat:
1760
1
    case lltok::kw_noinline:
1761
1
    case lltok::kw_nonlazybind:
1762
1
    case lltok::kw_noredzone:
1763
1
    case lltok::kw_noreturn:
1764
1
    case lltok::kw_nocf_check:
1765
1
    case lltok::kw_nounwind:
1766
1
    case lltok::kw_optforfuzzing:
1767
1
    case lltok::kw_optnone:
1768
1
    case lltok::kw_optsize:
1769
1
    case lltok::kw_returns_twice:
1770
1
    case lltok::kw_sanitize_address:
1771
1
    case lltok::kw_sanitize_hwaddress:
1772
1
    case lltok::kw_sanitize_memtag:
1773
1
    case lltok::kw_sanitize_memory:
1774
1
    case lltok::kw_sanitize_thread:
1775
1
    case lltok::kw_speculative_load_hardening:
1776
1
    case lltok::kw_ssp:
1777
1
    case lltok::kw_sspreq:
1778
1
    case lltok::kw_sspstrong:
1779
1
    case lltok::kw_safestack:
1780
1
    case lltok::kw_shadowcallstack:
1781
1
    case lltok::kw_strictfp:
1782
1
    case lltok::kw_uwtable:
1783
1
      HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
1784
1
      break;
1785
1
1786
1
    case lltok::kw_readnone:
1787
0
    case lltok::kw_readonly:
1788
0
      HaveError |= Error(Lex.getLoc(), "invalid use of attribute on return type");
1789
580k
    }
1790
580k
1791
580k
    Lex.Lex();
1792
10.6k
  }
1793
569k
}
1794
1795
410k
static unsigned parseOptionalLinkageAux(lltok::Kind Kind, bool &HasLinkage) {
1796
410k
  HasLinkage = true;
1797
410k
  switch (Kind) {
1798
410k
  default:
1799
388k
    HasLinkage = false;
1800
388k
    return GlobalValue::ExternalLinkage;
1801
410k
  case lltok::kw_private:
1802
2.10k
    return GlobalValue::PrivateLinkage;
1803
410k
  case lltok::kw_internal:
1804
3.98k
    return GlobalValue::InternalLinkage;
1805
410k
  case lltok::kw_weak:
1806
696
    return GlobalValue::WeakAnyLinkage;
1807
410k
  case lltok::kw_weak_odr:
1808
324
    return GlobalValue::WeakODRLinkage;
1809
410k
  case lltok::kw_linkonce:
1810
137
    return GlobalValue::LinkOnceAnyLinkage;
1811
410k
  case lltok::kw_linkonce_odr:
1812
1.02k
    return GlobalValue::LinkOnceODRLinkage;
1813
410k
  case lltok::kw_available_externally:
1814
142
    return GlobalValue::AvailableExternallyLinkage;
1815
410k
  case lltok::kw_appending:
1816
372
    return GlobalValue::AppendingLinkage;
1817
410k
  case lltok::kw_common:
1818
6.16k
    return GlobalValue::CommonLinkage;
1819
410k
  case lltok::kw_extern_weak:
1820
143
    return GlobalValue::ExternalWeakLinkage;
1821
410k
  case lltok::kw_external:
1822
7.08k
    return GlobalValue::ExternalLinkage;
1823
410k
  }
1824
410k
}
1825
1826
/// ParseOptionalLinkage
1827
///   ::= /*empty*/
1828
///   ::= 'private'
1829
///   ::= 'internal'
1830
///   ::= 'weak'
1831
///   ::= 'weak_odr'
1832
///   ::= 'linkonce'
1833
///   ::= 'linkonce_odr'
1834
///   ::= 'available_externally'
1835
///   ::= 'appending'
1836
///   ::= 'common'
1837
///   ::= 'extern_weak'
1838
///   ::= 'external'
1839
bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage,
1840
                                    unsigned &Visibility,
1841
                                    unsigned &DLLStorageClass,
1842
410k
                                    bool &DSOLocal) {
1843
410k
  Res = parseOptionalLinkageAux(Lex.getKind(), HasLinkage);
1844
410k
  if (HasLinkage)
1845
22.0k
    Lex.Lex();
1846
410k
  ParseOptionalDSOLocal(DSOLocal);
1847
410k
  ParseOptionalVisibility(Visibility);
1848
410k
  ParseOptionalDLLStorageClass(DLLStorageClass);
1849
410k
1850
410k
  if (DSOLocal && 
DLLStorageClass == GlobalValue::DLLImportStorageClass2.89k
) {
1851
1
    return Error(Lex.getLoc(), "dso_location and DLL-StorageClass mismatch");
1852
1
  }
1853
410k
1854
410k
  return false;
1855
410k
}
1856
1857
410k
void LLParser::ParseOptionalDSOLocal(bool &DSOLocal) {
1858
410k
  switch (Lex.getKind()) {
1859
410k
  default:
1860
407k
    DSOLocal = false;
1861
407k
    break;
1862
410k
  case lltok::kw_dso_local:
1863
2.89k
    DSOLocal = true;
1864
2.89k
    Lex.Lex();
1865
2.89k
    break;
1866
410k
  case lltok::kw_dso_preemptable:
1867
150
    DSOLocal = false;
1868
150
    Lex.Lex();
1869
150
    break;
1870
410k
  }
1871
410k
}
1872
1873
/// ParseOptionalVisibility
1874
///   ::= /*empty*/
1875
///   ::= 'default'
1876
///   ::= 'hidden'
1877
///   ::= 'protected'
1878
///
1879
410k
void LLParser::ParseOptionalVisibility(unsigned &Res) {
1880
410k
  switch (Lex.getKind()) {
1881
410k
  default:
1882
408k
    Res = GlobalValue::DefaultVisibility;
1883
408k
    return;
1884
410k
  case lltok::kw_default:
1885
20
    Res = GlobalValue::DefaultVisibility;
1886
20
    break;
1887
410k
  case lltok::kw_hidden:
1888
1.50k
    Res = GlobalValue::HiddenVisibility;
1889
1.50k
    break;
1890
410k
  case lltok::kw_protected:
1891
112
    Res = GlobalValue::ProtectedVisibility;
1892
112
    break;
1893
1.63k
  }
1894
1.63k
  Lex.Lex();
1895
1.63k
}
1896
1897
/// ParseOptionalDLLStorageClass
1898
///   ::= /*empty*/
1899
///   ::= 'dllimport'
1900
///   ::= 'dllexport'
1901
///
1902
410k
void LLParser::ParseOptionalDLLStorageClass(unsigned &Res) {
1903
410k
  switch (Lex.getKind()) {
1904
410k
  default:
1905
409k
    Res = GlobalValue::DefaultStorageClass;
1906
409k
    return;
1907
410k
  case lltok::kw_dllimport:
1908
146
    Res = GlobalValue::DLLImportStorageClass;
1909
146
    break;
1910
410k
  case lltok::kw_dllexport:
1911
323
    Res = GlobalValue::DLLExportStorageClass;
1912
323
    break;
1913
469
  }
1914
469
  Lex.Lex();
1915
469
}
1916
1917
/// ParseOptionalCallingConv
1918
///   ::= /*empty*/
1919
///   ::= 'ccc'
1920
///   ::= 'fastcc'
1921
///   ::= 'intel_ocl_bicc'
1922
///   ::= 'coldcc'
1923
///   ::= 'x86_stdcallcc'
1924
///   ::= 'x86_fastcallcc'
1925
///   ::= 'x86_thiscallcc'
1926
///   ::= 'x86_vectorcallcc'
1927
///   ::= 'arm_apcscc'
1928
///   ::= 'arm_aapcscc'
1929
///   ::= 'arm_aapcs_vfpcc'
1930
///   ::= 'aarch64_vector_pcs'
1931
///   ::= 'msp430_intrcc'
1932
///   ::= 'avr_intrcc'
1933
///   ::= 'avr_signalcc'
1934
///   ::= 'ptx_kernel'
1935
///   ::= 'ptx_device'
1936
///   ::= 'spir_func'
1937
///   ::= 'spir_kernel'
1938
///   ::= 'x86_64_sysvcc'
1939
///   ::= 'win64cc'
1940
///   ::= 'webkit_jscc'
1941
///   ::= 'anyregcc'
1942
///   ::= 'preserve_mostcc'
1943
///   ::= 'preserve_allcc'
1944
///   ::= 'ghccc'
1945
///   ::= 'swiftcc'
1946
///   ::= 'x86_intrcc'
1947
///   ::= 'hhvmcc'
1948
///   ::= 'hhvm_ccc'
1949
///   ::= 'cxx_fast_tlscc'
1950
///   ::= 'amdgpu_vs'
1951
///   ::= 'amdgpu_ls'
1952
///   ::= 'amdgpu_hs'
1953
///   ::= 'amdgpu_es'
1954
///   ::= 'amdgpu_gs'
1955
///   ::= 'amdgpu_ps'
1956
///   ::= 'amdgpu_cs'
1957
///   ::= 'amdgpu_kernel'
1958
///   ::= 'cc' UINT
1959
///
1960
569k
bool LLParser::ParseOptionalCallingConv(unsigned &CC) {
1961
569k
  switch (Lex.getKind()) {
1962
569k
  
default: CC = CallingConv::C; return false535k
;
1963
569k
  
case lltok::kw_ccc: CC = CallingConv::C; break18
;
1964
569k
  
case lltok::kw_fastcc: CC = CallingConv::Fast; break1.97k
;
1965
569k
  
case lltok::kw_coldcc: CC = CallingConv::Cold; break125
;
1966
569k
  
case lltok::kw_x86_stdcallcc: CC = CallingConv::X86_StdCall; break88
;
1967
569k
  
case lltok::kw_x86_fastcallcc: CC = CallingConv::X86_FastCall; break108
;
1968
569k
  
case lltok::kw_x86_regcallcc: CC = CallingConv::X86_RegCall; break200
;
1969
569k
  
case lltok::kw_x86_thiscallcc: CC = CallingConv::X86_ThisCall; break348
;
1970
569k
  
case lltok::kw_x86_vectorcallcc:CC = CallingConv::X86_VectorCall; break71
;
1971
569k
  
case lltok::kw_arm_apcscc: CC = CallingConv::ARM_APCS; break40
;
1972
569k
  
case lltok::kw_arm_aapcscc: CC = CallingConv::ARM_AAPCS; break800
;
1973
569k
  
case lltok::kw_arm_aapcs_vfpcc:CC = CallingConv::ARM_AAPCS_VFP; break1.47k
;
1974
569k
  
case lltok::kw_aarch64_vector_pcs:CC = CallingConv::AArch64_VectorCall; break17
;
1975
569k
  
case lltok::kw_msp430_intrcc: CC = CallingConv::MSP430_INTR; break14
;
1976
569k
  
case lltok::kw_avr_intrcc: CC = CallingConv::AVR_INTR; break3
;
1977
569k
  
case lltok::kw_avr_signalcc: CC = CallingConv::AVR_SIGNAL; break3
;
1978
569k
  
case lltok::kw_ptx_kernel: CC = CallingConv::PTX_Kernel; break21
;
1979
569k
  
case lltok::kw_ptx_device: CC = CallingConv::PTX_Device; break185
;
1980
569k
  
case lltok::kw_spir_kernel: CC = CallingConv::SPIR_KERNEL; break23
;
1981
569k
  
case lltok::kw_spir_func: CC = CallingConv::SPIR_FUNC; break73
;
1982
569k
  
case lltok::kw_intel_ocl_bicc: CC = CallingConv::Intel_OCL_BI; break92
;
1983
569k
  
case lltok::kw_x86_64_sysvcc: CC = CallingConv::X86_64_SysV; break11
;
1984
569k
  
case lltok::kw_win64cc: CC = CallingConv::Win64; break46
;
1985
569k
  
case lltok::kw_webkit_jscc: CC = CallingConv::WebKit_JS; break33
;
1986
569k
  
case lltok::kw_anyregcc: CC = CallingConv::AnyReg; break84
;
1987
569k
  
case lltok::kw_preserve_mostcc:CC = CallingConv::PreserveMost; break15
;
1988
569k
  
case lltok::kw_preserve_allcc: CC = CallingConv::PreserveAll; break11
;
1989
569k
  
case lltok::kw_ghccc: CC = CallingConv::GHC; break58
;
1990
569k
  
case lltok::kw_swiftcc: CC = CallingConv::Swift; break471
;
1991
569k
  
case lltok::kw_x86_intrcc: CC = CallingConv::X86_INTR; break42
;
1992
569k
  
case lltok::kw_hhvmcc: CC = CallingConv::HHVM; break27
;
1993
569k
  
case lltok::kw_hhvm_ccc: CC = CallingConv::HHVM_C; break16
;
1994
569k
  
case lltok::kw_cxx_fast_tlscc: CC = CallingConv::CXX_FAST_TLS; break108
;
1995
569k
  
case lltok::kw_amdgpu_vs: CC = CallingConv::AMDGPU_VS; break236
;
1996
569k
  
case lltok::kw_amdgpu_ls: CC = CallingConv::AMDGPU_LS; break8
;
1997
569k
  
case lltok::kw_amdgpu_hs: CC = CallingConv::AMDGPU_HS; break30
;
1998
569k
  
case lltok::kw_amdgpu_es: CC = CallingConv::AMDGPU_ES; break8
;
1999
569k
  
case lltok::kw_amdgpu_gs: CC = CallingConv::AMDGPU_GS; break133
;
2000
569k
  
case lltok::kw_amdgpu_ps: CC = CallingConv::AMDGPU_PS; break2.81k
;
2001
569k
  
case lltok::kw_amdgpu_cs: CC = CallingConv::AMDGPU_CS; break93
;
2002
569k
  
case lltok::kw_amdgpu_kernel: CC = CallingConv::AMDGPU_KERNEL; break24.5k
;
2003
569k
  case lltok::kw_cc: {
2004
112
      Lex.Lex();
2005
112
      return ParseUInt32(CC);
2006
34.4k
    }
2007
34.4k
  }
2008
34.4k
2009
34.4k
  Lex.Lex();
2010
34.4k
  return false;
2011
34.4k
}
2012
2013
/// ParseMetadataAttachment
2014
///   ::= !dbg !42
2015
42.1k
bool LLParser::ParseMetadataAttachment(unsigned &Kind, MDNode *&MD) {
2016
42.1k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata attachment");
2017
42.1k
2018
42.1k
  std::string Name = Lex.getStrVal();
2019
42.1k
  Kind = M->getMDKindID(Name);
2020
42.1k
  Lex.Lex();
2021
42.1k
2022
42.1k
  return ParseMDNode(MD);
2023
42.1k
}
2024
2025
/// ParseInstructionMetadata
2026
///   ::= !dbg !42 (',' !dbg !57)*
2027
33.4k
bool LLParser::ParseInstructionMetadata(Instruction &Inst) {
2028
35.1k
  do {
2029
35.1k
    if (Lex.getKind() != lltok::MetadataVar)
2030
2
      return TokError("expected metadata after comma");
2031
35.1k
2032
35.1k
    unsigned MDK;
2033
35.1k
    MDNode *N;
2034
35.1k
    if (ParseMetadataAttachment(MDK, N))
2035
2
      return true;
2036
35.1k
2037
35.1k
    Inst.setMetadata(MDK, N);
2038
35.1k
    if (MDK == LLVMContext::MD_tbaa)
2039
4.63k
      InstsWithTBAATag.push_back(&Inst);
2040
35.1k
2041
35.1k
    // If this is the end of the list, we're done.
2042
35.1k
  } while (EatIfPresent(lltok::comma));
2043
33.4k
  
return false33.4k
;
2044
33.4k
}
2045
2046
/// ParseGlobalObjectMetadataAttachment
2047
///   ::= !dbg !57
2048
6.99k
bool LLParser::ParseGlobalObjectMetadataAttachment(GlobalObject &GO) {
2049
6.99k
  unsigned MDK;
2050
6.99k
  MDNode *N;
2051
6.99k
  if (ParseMetadataAttachment(MDK, N))
2052
0
    return true;
2053
6.99k
2054
6.99k
  GO.addMetadata(MDK, *N);
2055
6.99k
  return false;
2056
6.99k
}
2057
2058
/// ParseOptionalFunctionMetadata
2059
///   ::= (!dbg !57)*
2060
297k
bool LLParser::ParseOptionalFunctionMetadata(Function &F) {
2061
302k
  while (Lex.getKind() == lltok::MetadataVar)
2062
5.25k
    if (ParseGlobalObjectMetadataAttachment(F))
2063
0
      return true;
2064
297k
  return false;
2065
297k
}
2066
2067
/// ParseOptionalAlignment
2068
///   ::= /* empty */
2069
///   ::= 'align' 4
2070
684k
bool LLParser::ParseOptionalAlignment(unsigned &Alignment) {
2071
684k
  Alignment = 0;
2072
684k
  if (!EatIfPresent(lltok::kw_align))
2073
378k
    return false;
2074
305k
  LocTy AlignLoc = Lex.getLoc();
2075
305k
  if (ParseUInt32(Alignment)) 
return true0
;
2076
305k
  if (!isPowerOf2_32(Alignment))
2077
1
    return Error(AlignLoc, "alignment is not a power of two");
2078
305k
  if (Alignment > Value::MaximumAlignment)
2079
3
    return Error(AlignLoc, "huge alignments are not supported yet");
2080
305k
  return false;
2081
305k
}
2082
2083
/// ParseOptionalDerefAttrBytes
2084
///   ::= /* empty */
2085
///   ::= AttrKind '(' 4 ')'
2086
///
2087
/// where AttrKind is either 'dereferenceable' or 'dereferenceable_or_null'.
2088
bool LLParser::ParseOptionalDerefAttrBytes(lltok::Kind AttrKind,
2089
763
                                           uint64_t &Bytes) {
2090
763
  assert((AttrKind == lltok::kw_dereferenceable ||
2091
763
          AttrKind == lltok::kw_dereferenceable_or_null) &&
2092
763
         "contract!");
2093
763
2094
763
  Bytes = 0;
2095
763
  if (!EatIfPresent(AttrKind))
2096
0
    return false;
2097
763
  LocTy ParenLoc = Lex.getLoc();
2098
763
  if (!EatIfPresent(lltok::lparen))
2099
0
    return Error(ParenLoc, "expected '('");
2100
763
  LocTy DerefLoc = Lex.getLoc();
2101
763
  if (ParseUInt64(Bytes)) 
return true0
;
2102
763
  ParenLoc = Lex.getLoc();
2103
763
  if (!EatIfPresent(lltok::rparen))
2104
0
    return Error(ParenLoc, "expected ')'");
2105
763
  if (!Bytes)
2106
0
    return Error(DerefLoc, "dereferenceable bytes must be non-zero");
2107
763
  return false;
2108
763
}
2109
2110
/// ParseOptionalCommaAlign
2111
///   ::=
2112
///   ::= ',' align 4
2113
///
2114
/// This returns with AteExtraComma set to true if it ate an excess comma at the
2115
/// end.
2116
bool LLParser::ParseOptionalCommaAlign(unsigned &Alignment,
2117
343k
                                       bool &AteExtraComma) {
2118
343k
  AteExtraComma = false;
2119
578k
  while (EatIfPresent(lltok::comma)) {
2120
245k
    // Metadata at the end is an early exit.
2121
245k
    if (Lex.getKind() == lltok::MetadataVar) {
2122
10.4k
      AteExtraComma = true;
2123
10.4k
      return false;
2124
10.4k
    }
2125
234k
2126
234k
    if (Lex.getKind() != lltok::kw_align)
2127
0
      return Error(Lex.getLoc(), "expected metadata or 'align'");
2128
234k
2129
234k
    if (ParseOptionalAlignment(Alignment)) 
return true2
;
2130
234k
  }
2131
343k
2132
343k
  
return false333k
;
2133
343k
}
2134
2135
/// ParseOptionalCommaAddrSpace
2136
///   ::=
2137
///   ::= ',' addrspace(1)
2138
///
2139
/// This returns with AteExtraComma set to true if it ate an excess comma at the
2140
/// end.
2141
bool LLParser::ParseOptionalCommaAddrSpace(unsigned &AddrSpace,
2142
                                           LocTy &Loc,
2143
47.1k
                                           bool &AteExtraComma) {
2144
47.1k
  AteExtraComma = false;
2145
47.8k
  while (EatIfPresent(lltok::comma)) {
2146
708
    // Metadata at the end is an early exit.
2147
708
    if (Lex.getKind() == lltok::MetadataVar) {
2148
51
      AteExtraComma = true;
2149
51
      return false;
2150
51
    }
2151
657
2152
657
    Loc = Lex.getLoc();
2153
657
    if (Lex.getKind() != lltok::kw_addrspace)
2154
0
      return Error(Lex.getLoc(), "expected metadata or 'addrspace'");
2155
657
2156
657
    if (ParseOptionalAddrSpace(AddrSpace))
2157
0
      return true;
2158
657
  }
2159
47.1k
2160
47.1k
  
return false47.1k
;
2161
47.1k
}
2162
2163
bool LLParser::parseAllocSizeArguments(unsigned &BaseSizeArg,
2164
25
                                       Optional<unsigned> &HowManyArg) {
2165
25
  Lex.Lex();
2166
25
2167
25
  auto StartParen = Lex.getLoc();
2168
25
  if (!EatIfPresent(lltok::lparen))
2169
0
    return Error(StartParen, "expected '('");
2170
25
2171
25
  if (ParseUInt32(BaseSizeArg))
2172
0
    return true;
2173
25
2174
25
  if (EatIfPresent(lltok::comma)) {
2175
12
    auto HowManyAt = Lex.getLoc();
2176
12
    unsigned HowMany;
2177
12
    if (ParseUInt32(HowMany))
2178
0
      return true;
2179
12
    if (HowMany == BaseSizeArg)
2180
1
      return Error(HowManyAt,
2181
1
                   "'allocsize' indices can't refer to the same parameter");
2182
11
    HowManyArg = HowMany;
2183
11
  } else
2184
13
    HowManyArg = None;
2185
25
2186
25
  auto EndParen = Lex.getLoc();
2187
24
  if (!EatIfPresent(lltok::rparen))
2188
0
    return Error(EndParen, "expected ')'");
2189
24
  return false;
2190
24
}
2191
2192
/// ParseScopeAndOrdering
2193
///   if isAtomic: ::= SyncScope? AtomicOrdering
2194
///   else: ::=
2195
///
2196
/// This sets Scope and Ordering to the parsed values.
2197
bool LLParser::ParseScopeAndOrdering(bool isAtomic, SyncScope::ID &SSID,
2198
355k
                                     AtomicOrdering &Ordering) {
2199
355k
  if (!isAtomic)
2200
340k
    return false;
2201
14.6k
2202
14.6k
  return ParseScope(SSID) || ParseOrdering(Ordering);
2203
14.6k
}
2204
2205
/// ParseScope
2206
///   ::= syncscope("singlethread" | "<target scope>")?
2207
///
2208
/// This sets synchronization scope ID to the ID of the parsed value.
2209
14.6k
bool LLParser::ParseScope(SyncScope::ID &SSID) {
2210
14.6k
  SSID = SyncScope::System;
2211
14.6k
  if (EatIfPresent(lltok::kw_syncscope)) {
2212
2.54k
    auto StartParenAt = Lex.getLoc();
2213
2.54k
    if (!EatIfPresent(lltok::lparen))
2214
0
      return Error(StartParenAt, "Expected '(' in syncscope");
2215
2.54k
2216
2.54k
    std::string SSN;
2217
2.54k
    auto SSNAt = Lex.getLoc();
2218
2.54k
    if (ParseStringConstant(SSN))
2219
0
      return Error(SSNAt, "Expected synchronization scope name");
2220
2.54k
2221
2.54k
    auto EndParenAt = Lex.getLoc();
2222
2.54k
    if (!EatIfPresent(lltok::rparen))
2223
0
      return Error(EndParenAt, "Expected ')' in syncscope");
2224
2.54k
2225
2.54k
    SSID = Context.getOrInsertSyncScopeID(SSN);
2226
2.54k
  }
2227
14.6k
2228
14.6k
  return false;
2229
14.6k
}
2230
2231
/// ParseOrdering
2232
///   ::= AtomicOrdering
2233
///
2234
/// This sets Ordering to the parsed value.
2235
16.5k
bool LLParser::ParseOrdering(AtomicOrdering &Ordering) {
2236
16.5k
  switch (Lex.getKind()) {
2237
16.5k
  
default: return TokError("Expected ordering on atomic instruction")0
;
2238
16.5k
  
case lltok::kw_unordered: Ordering = AtomicOrdering::Unordered; break1.11k
;
2239
16.5k
  
case lltok::kw_monotonic: Ordering = AtomicOrdering::Monotonic; break3.59k
;
2240
16.5k
  // Not specified yet:
2241
16.5k
  // case lltok::kw_consume: Ordering = AtomicOrdering::Consume; break;
2242
16.5k
  
case lltok::kw_acquire: Ordering = AtomicOrdering::Acquire; break2.46k
;
2243
16.5k
  
case lltok::kw_release: Ordering = AtomicOrdering::Release; break1.61k
;
2244
16.5k
  
case lltok::kw_acq_rel: Ordering = AtomicOrdering::AcquireRelease; break1.25k
;
2245
16.5k
  case lltok::kw_seq_cst:
2246
6.53k
    Ordering = AtomicOrdering::SequentiallyConsistent;
2247
6.53k
    break;
2248
16.5k
  }
2249
16.5k
  Lex.Lex();
2250
16.5k
  return false;
2251
16.5k
}
2252
2253
/// ParseOptionalStackAlignment
2254
///   ::= /* empty */
2255
///   ::= 'alignstack' '(' 4 ')'
2256
34
bool LLParser::ParseOptionalStackAlignment(unsigned &Alignment) {
2257
34
  Alignment = 0;
2258
34
  if (!EatIfPresent(lltok::kw_alignstack))
2259
0
    return false;
2260
34
  LocTy ParenLoc = Lex.getLoc();
2261
34
  if (!EatIfPresent(lltok::lparen))
2262
0
    return Error(ParenLoc, "expected '('");
2263
34
  LocTy AlignLoc = Lex.getLoc();
2264
34
  if (ParseUInt32(Alignment)) 
return true0
;
2265
34
  ParenLoc = Lex.getLoc();
2266
34
  if (!EatIfPresent(lltok::rparen))
2267
0
    return Error(ParenLoc, "expected ')'");
2268
34
  if (!isPowerOf2_32(Alignment))
2269
0
    return Error(AlignLoc, "stack alignment is not a power of two");
2270
34
  return false;
2271
34
}
2272
2273
/// ParseIndexList - This parses the index list for an insert/extractvalue
2274
/// instruction.  This sets AteExtraComma in the case where we eat an extra
2275
/// comma at the end of the line and find that it is followed by metadata.
2276
/// Clients that don't allow metadata can call the version of this function that
2277
/// only takes one argument.
2278
///
2279
/// ParseIndexList
2280
///    ::=  (',' uint32)+
2281
///
2282
bool LLParser::ParseIndexList(SmallVectorImpl<unsigned> &Indices,
2283
15.7k
                              bool &AteExtraComma) {
2284
15.7k
  AteExtraComma = false;
2285
15.7k
2286
15.7k
  if (Lex.getKind() != lltok::comma)
2287
0
    return TokError("expected ',' as start of index list");
2288
15.7k
2289
31.8k
  
while (15.7k
EatIfPresent(lltok::comma)) {
2290
16.1k
    if (Lex.getKind() == lltok::MetadataVar) {
2291
76
      if (Indices.empty()) 
return TokError("expected index")1
;
2292
75
      AteExtraComma = true;
2293
75
      return false;
2294
75
    }
2295
16.0k
    unsigned Idx = 0;
2296
16.0k
    if (ParseUInt32(Idx)) 
return true0
;
2297
16.0k
    Indices.push_back(Idx);
2298
16.0k
  }
2299
15.7k
2300
15.7k
  
return false15.6k
;
2301
15.7k
}
2302
2303
//===----------------------------------------------------------------------===//
2304
// Type Parsing.
2305
//===----------------------------------------------------------------------===//
2306
2307
/// ParseType - Parse a type.
2308
7.61M
bool LLParser::ParseType(Type *&Result, const Twine &Msg, bool AllowVoid) {
2309
7.61M
  SMLoc TypeLoc = Lex.getLoc();
2310
7.61M
  switch (Lex.getKind()) {
2311
7.61M
  default:
2312
5
    return TokError(Msg);
2313
7.61M
  case lltok::Type:
2314
5.77M
    // Type ::= 'float' | 'void' (etc)
2315
5.77M
    Result = Lex.getTyVal();
2316
5.77M
    Lex.Lex();
2317
5.77M
    break;
2318
7.61M
  case lltok::lbrace:
2319
40.6k
    // Type ::= StructType
2320
40.6k
    if (ParseAnonStructType(Result, false))
2321
1
      return true;
2322
40.6k
    break;
2323
198k
  case lltok::lsquare:
2324
198k
    // Type ::= '[' ... ']'
2325
198k
    Lex.Lex(); // eat the lsquare.
2326
198k
    if (ParseArrayVectorType(Result, false))
2327
3
      return true;
2328
198k
    break;
2329
1.50M
  case lltok::less: // Either vector or packed struct.
2330
1.50M
    // Type ::= '<' ... '>'
2331
1.50M
    Lex.Lex();
2332
1.50M
    if (Lex.getKind() == lltok::lbrace) {
2333
835
      if (ParseAnonStructType(Result, true) ||
2334
835
          ParseToken(lltok::greater, "expected '>' at end of packed struct"))
2335
0
        return true;
2336
1.50M
    } else if (ParseArrayVectorType(Result, true))
2337
0
      return true;
2338
1.50M
    break;
2339
1.50M
  case lltok::LocalVar: {
2340
91.8k
    // Type ::= %foo
2341
91.8k
    std::pair<Type*, LocTy> &Entry = NamedTypes[Lex.getStrVal()];
2342
91.8k
2343
91.8k
    // If the type hasn't been defined yet, create a forward definition and
2344
91.8k
    // remember where that forward def'n was seen (in case it never is defined).
2345
91.8k
    if (!Entry.first) {
2346
4.21k
      Entry.first = StructType::create(Context, Lex.getStrVal());
2347
4.21k
      Entry.second = Lex.getLoc();
2348
4.21k
    }
2349
91.8k
    Result = Entry.first;
2350
91.8k
    Lex.Lex();
2351
91.8k
    break;
2352
1.50M
  }
2353
1.50M
2354
1.50M
  case lltok::LocalVarID: {
2355
2.64k
    // Type ::= %4
2356
2.64k
    std::pair<Type*, LocTy> &Entry = NumberedTypes[Lex.getUIntVal()];
2357
2.64k
2358
2.64k
    // If the type hasn't been defined yet, create a forward definition and
2359
2.64k
    // remember where that forward def'n was seen (in case it never is defined).
2360
2.64k
    if (!Entry.first) {
2361
281
      Entry.first = StructType::create(Context);
2362
281
      Entry.second = Lex.getLoc();
2363
281
    }
2364
2.64k
    Result = Entry.first;
2365
2.64k
    Lex.Lex();
2366
2.64k
    break;
2367
7.61M
  }
2368
7.61M
  }
2369
7.61M
2370
7.61M
  // Parse the type suffixes.
2371
8.54M
  
while (7.61M
true) {
2372
8.54M
    switch (Lex.getKind()) {
2373
8.54M
    // End of type.
2374
8.54M
    default:
2375
7.61M
      if (!AllowVoid && 
Result->isVoidTy()6.74M
)
2376
1
        return Error(TypeLoc, "void type only allowed for function results");
2377
7.61M
      return false;
2378
7.61M
2379
7.61M
    // Type ::= Type '*'
2380
7.61M
    case lltok::star:
2381
793k
      if (Result->isLabelTy())
2382
1
        return TokError("basic block pointers are invalid");
2383
793k
      if (Result->isVoidTy())
2384
0
        return TokError("pointers to void are invalid - use i8* instead");
2385
793k
      if (!PointerType::isValidElementType(Result))
2386
0
        return TokError("pointer to this type is invalid");
2387
793k
      Result = PointerType::getUnqual(Result);
2388
793k
      Lex.Lex();
2389
793k
      break;
2390
793k
2391
793k
    // Type ::= Type 'addrspace' '(' uint32 ')' '*'
2392
793k
    case lltok::kw_addrspace: {
2393
115k
      if (Result->isLabelTy())
2394
0
        return TokError("basic block pointers are invalid");
2395
115k
      if (Result->isVoidTy())
2396
0
        return TokError("pointers to void are invalid; use i8* instead");
2397
115k
      if (!PointerType::isValidElementType(Result))
2398
0
        return TokError("pointer to this type is invalid");
2399
115k
      unsigned AddrSpace;
2400
115k
      if (ParseOptionalAddrSpace(AddrSpace) ||
2401
115k
          ParseToken(lltok::star, "expected '*' in address space"))
2402
0
        return true;
2403
115k
2404
115k
      Result = PointerType::get(Result, AddrSpace);
2405
115k
      break;
2406
115k
    }
2407
115k
2408
115k
    /// Types '(' ArgTypeListI ')' OptFuncAttrs
2409
115k
    case lltok::lparen:
2410
21.2k
      if (ParseFunctionType(Result))
2411
0
        return true;
2412
21.2k
      break;
2413
8.54M
    }
2414
8.54M
  }
2415
7.61M
}
2416
2417
/// ParseParameterList
2418
///    ::= '(' ')'
2419
///    ::= '(' Arg (',' Arg)* ')'
2420
///  Arg
2421
///    ::= Type OptionalAttributes Value OptionalAttributes
2422
bool LLParser::ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
2423
                                  PerFunctionState &PFS, bool IsMustTailCall,
2424
191k
                                  bool InVarArgsFunc) {
2425
191k
  if (ParseToken(lltok::lparen, "expected '(' in call"))
2426
0
    return true;
2427
191k
2428
579k
  
while (191k
Lex.getKind() != lltok::rparen) {
2429
388k
    // If this isn't the first argument, we need a comma.
2430
388k
    if (!ArgList.empty() &&
2431
388k
        
ParseToken(lltok::comma, "expected ',' in argument list")227k
)
2432
0
      return true;
2433
388k
2434
388k
    // Parse an ellipsis if this is a musttail call in a variadic function.
2435
388k
    if (Lex.getKind() == lltok::dotdotdot) {
2436
53
      const char *Msg = "unexpected ellipsis in argument list for ";
2437
53
      if (!IsMustTailCall)
2438
0
        return TokError(Twine(Msg) + "non-musttail call");
2439
53
      if (!InVarArgsFunc)
2440
1
        return TokError(Twine(Msg) + "musttail call in non-varargs function");
2441
52
      Lex.Lex();  // Lex the '...', it is purely for readability.
2442
52
      return ParseToken(lltok::rparen, "expected ')' at end of argument list");
2443
52
    }
2444
388k
2445
388k
    // Parse the argument.
2446
388k
    LocTy ArgLoc;
2447
388k
    Type *ArgTy = nullptr;
2448
388k
    AttrBuilder ArgAttrs;
2449
388k
    Value *V;
2450
388k
    if (ParseType(ArgTy, ArgLoc))
2451
0
      return true;
2452
388k
2453
388k
    if (ArgTy->isMetadataTy()) {
2454
25.2k
      if (ParseMetadataAsValue(V, PFS))
2455
3
        return true;
2456
363k
    } else {
2457
363k
      // Otherwise, handle normal operands.
2458
363k
      if (ParseOptionalParamAttrs(ArgAttrs) || 
ParseValue(ArgTy, V, PFS)363k
)
2459
3
        return true;
2460
388k
    }
2461
388k
    ArgList.push_back(ParamInfo(
2462
388k
        ArgLoc, V, AttributeSet::get(V->getContext(), ArgAttrs)));
2463
388k
  }
2464
191k
2465
191k
  
if (190k
IsMustTailCall190k
&&
InVarArgsFunc150
)
2466
1
    return TokError("expected '...' at end of argument list for musttail call "
2467
1
                    "in varargs function");
2468
190k
2469
190k
  Lex.Lex();  // Lex the ')'.
2470
190k
  return false;
2471
190k
}
2472
2473
/// ParseByValWithOptionalType
2474
///   ::= byval
2475
///   ::= byval(<ty>)
2476
1.77k
bool LLParser::ParseByValWithOptionalType(Type *&Result) {
2477
1.77k
  Result = nullptr;
2478
1.77k
  if (!EatIfPresent(lltok::kw_byval))
2479
0
    return true;
2480
1.77k
  if (!EatIfPresent(lltok::lparen))
2481
1.72k
    return false;
2482
47
  if (ParseType(Result))
2483
1
    return true;
2484
46
  if (!EatIfPresent(lltok::rparen))
2485
0
    return Error(Lex.getLoc(), "expected ')'");
2486
46
  return false;
2487
46
}
2488
2489
/// ParseOptionalOperandBundles
2490
///    ::= /*empty*/
2491
///    ::= '[' OperandBundle [, OperandBundle ]* ']'
2492
///
2493
/// OperandBundle
2494
///    ::= bundle-tag '(' ')'
2495
///    ::= bundle-tag '(' Type Value [, Type Value ]* ')'
2496
///
2497
/// bundle-tag ::= String Constant
2498
bool LLParser::ParseOptionalOperandBundles(
2499
191k
    SmallVectorImpl<OperandBundleDef> &BundleList, PerFunctionState &PFS) {
2500
191k
  LocTy BeginLoc = Lex.getLoc();
2501
191k
  if (!EatIfPresent(lltok::lsquare))
2502
189k
    return false;
2503
1.77k
2504
3.59k
  
while (1.77k
Lex.getKind() != lltok::rsquare) {
2505
1.81k
    // If this isn't the first operand bundle, we need a comma.
2506
1.81k
    if (!BundleList.empty() &&
2507
1.81k
        
ParseToken(lltok::comma, "expected ',' in input list")40
)
2508
0
      return true;
2509
1.81k
2510
1.81k
    std::string Tag;
2511
1.81k
    if (ParseStringConstant(Tag))
2512
0
      return true;
2513
1.81k
2514
1.81k
    if (ParseToken(lltok::lparen, "expected '(' in operand bundle"))
2515
0
      return true;
2516
1.81k
2517
1.81k
    std::vector<Value *> Inputs;
2518
3.18k
    while (Lex.getKind() != lltok::rparen) {
2519
1.37k
      // If this isn't the first input, we need a comma.
2520
1.37k
      if (!Inputs.empty() &&
2521
1.37k
          
ParseToken(lltok::comma, "expected ',' in input list")576
)
2522
0
        return true;
2523
1.37k
2524
1.37k
      Type *Ty = nullptr;
2525
1.37k
      Value *Input = nullptr;
2526
1.37k
      if (ParseType(Ty) || ParseValue(Ty, Input, PFS))
2527
0
        return true;
2528
1.37k
      Inputs.push_back(Input);
2529
1.37k
    }
2530
1.81k
2531
1.81k
    BundleList.emplace_back(std::move(Tag), std::move(Inputs));
2532
1.81k
2533
1.81k
    Lex.Lex(); // Lex the ')'.
2534
1.81k
  }
2535
1.77k
2536
1.77k
  if (BundleList.empty())
2537
0
    return Error(BeginLoc, "operand bundle set must not be empty");
2538
1.77k
2539
1.77k
  Lex.Lex(); // Lex the ']'.
2540
1.77k
  return false;
2541
1.77k
}
2542
2543
/// ParseArgumentList - Parse the argument list for a function type or function
2544
/// prototype.
2545
///   ::= '(' ArgTypeListI ')'
2546
/// ArgTypeListI
2547
///   ::= /*empty*/
2548
///   ::= '...'
2549
///   ::= ArgTypeList ',' '...'
2550
///   ::= ArgType (',' ArgType)*
2551
///
2552
bool LLParser::ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
2553
399k
                                 bool &isVarArg){
2554
399k
  isVarArg = false;
2555
399k
  assert(Lex.getKind() == lltok::lparen);
2556
399k
  Lex.Lex(); // eat the (.
2557
399k
2558
399k
  if (Lex.getKind() == lltok::rparen) {
2559
56.1k
    // empty
2560
343k
  } else if (Lex.getKind() == lltok::dotdotdot) {
2561
7.56k
    isVarArg = true;
2562
7.56k
    Lex.Lex();
2563
336k
  } else {
2564
336k
    LocTy TypeLoc = Lex.getLoc();
2565
336k
    Type *ArgTy = nullptr;
2566
336k
    AttrBuilder Attrs;
2567
336k
    std::string Name;
2568
336k
2569
336k
    if (ParseType(ArgTy) ||
2570
336k
        
ParseOptionalParamAttrs(Attrs)336k
)
return true3
;
2571
336k
2572
336k
    if (ArgTy->isVoidTy())
2573
0
      return Error(TypeLoc, "argument can not have void type");
2574
336k
2575
336k
    if (Lex.getKind() == lltok::LocalVar) {
2576
255k
      Name = Lex.getStrVal();
2577
255k
      Lex.Lex();
2578
255k
    }
2579
336k
2580
336k
    if (!FunctionType::isValidArgumentType(ArgTy))
2581
0
      return Error(TypeLoc, "invalid type for function argument");
2582
336k
2583
336k
    ArgList.emplace_back(TypeLoc, ArgTy,
2584
336k
                         AttributeSet::get(ArgTy->getContext(), Attrs),
2585
336k
                         std::move(Name));
2586
336k
2587
679k
    while (EatIfPresent(lltok::comma)) {
2588
347k
      // Handle ... at end of arg list.
2589
347k
      if (EatIfPresent(lltok::dotdotdot)) {
2590
5.12k
        isVarArg = true;
2591
5.12k
        break;
2592
5.12k
      }
2593
342k
2594
342k
      // Otherwise must be an argument type.
2595
342k
      TypeLoc = Lex.getLoc();
2596
342k
      if (ParseType(ArgTy) || ParseOptionalParamAttrs(Attrs)) 
return true0
;
2597
342k
2598
342k
      if (ArgTy->isVoidTy())
2599
0
        return Error(TypeLoc, "argument can not have void type");
2600
342k
2601
342k
      if (Lex.getKind() == lltok::LocalVar) {
2602
244k
        Name = Lex.getStrVal();
2603
244k
        Lex.Lex();
2604
244k
      } else {
2605
97.9k
        Name = "";
2606
97.9k
      }
2607
342k
2608
342k
      if (!ArgTy->isFirstClassType())
2609
0
        return Error(TypeLoc, "invalid type for function argument");
2610
342k
2611
342k
      ArgList.emplace_back(TypeLoc, ArgTy,
2612
342k
                           AttributeSet::get(ArgTy->getContext(), Attrs),
2613
342k
                           std::move(Name));
2614
342k
    }
2615
336k
  }
2616
399k
2617
399k
  
return ParseToken(lltok::rparen, "expected ')' at end of argument list")399k
;
2618
399k
}
2619
2620
/// ParseFunctionType
2621
///  ::= Type ArgumentList OptionalAttrs
2622
21.2k
bool LLParser::ParseFunctionType(Type *&Result) {
2623
21.2k
  assert(Lex.getKind() == lltok::lparen);
2624
21.2k
2625
21.2k
  if (!FunctionType::isValidReturnType(Result))
2626
0
    return TokError("invalid function return type");
2627
21.2k
2628
21.2k
  SmallVector<ArgInfo, 8> ArgList;
2629
21.2k
  bool isVarArg;
2630
21.2k
  if (ParseArgumentList(ArgList, isVarArg))
2631
0
    return true;
2632
21.2k
2633
21.2k
  // Reject names on the arguments lists.
2634
40.4k
  
for (unsigned i = 0, e = ArgList.size(); 21.2k
i != e;
++i19.1k
) {
2635
19.1k
    if (!ArgList[i].Name.empty())
2636
0
      return Error(ArgList[i].Loc, "argument name invalid in function type");
2637
19.1k
    if (ArgList[i].Attrs.hasAttributes())
2638
0
      return Error(ArgList[i].Loc,
2639
0
                   "argument attributes invalid in function type");
2640
19.1k
  }
2641
21.2k
2642
21.2k
  SmallVector<Type*, 16> ArgListTy;
2643
40.4k
  for (unsigned i = 0, e = ArgList.size(); i != e; 
++i19.1k
)
2644
19.1k
    ArgListTy.push_back(ArgList[i].Ty);
2645
21.2k
2646
21.2k
  Result = FunctionType::get(Result, ArgListTy, isVarArg);
2647
21.2k
  return false;
2648
21.2k
}
2649
2650
/// ParseAnonStructType - Parse an anonymous struct type, which is inlined into
2651
/// other structs.
2652
41.5k
bool LLParser::ParseAnonStructType(Type *&Result, bool Packed) {
2653
41.5k
  SmallVector<Type*, 8> Elts;
2654
41.5k
  if (ParseStructBody(Elts)) 
return true1
;
2655
41.5k
2656
41.5k
  Result = StructType::get(Context, Elts, Packed);
2657
41.5k
  return false;
2658
41.5k
}
2659
2660
/// ParseStructDefinition - Parse a struct in a 'type' definition.
2661
bool LLParser::ParseStructDefinition(SMLoc TypeLoc, StringRef Name,
2662
                                     std::pair<Type*, LocTy> &Entry,
2663
13.3k
                                     Type *&ResultTy) {
2664
13.3k
  // If the type was already defined, diagnose the redefinition.
2665
13.3k
  if (Entry.first && 
!Entry.second.isValid()4.49k
)
2666
0
    return Error(TypeLoc, "redefinition of type");
2667
13.3k
2668
13.3k
  // If we have opaque, just return without filling in the definition for the
2669
13.3k
  // struct.  This counts as a definition as far as the .ll file goes.
2670
13.3k
  if (EatIfPresent(lltok::kw_opaque)) {
2671
809
    // This type is being defined, so clear the location to indicate this.
2672
809
    Entry.second = SMLoc();
2673
809
2674
809
    // If this type number has never been uttered, create it.
2675
809
    if (!Entry.first)
2676
486
      Entry.first = StructType::create(Context, Name);
2677
809
    ResultTy = Entry.first;
2678
809
    return false;
2679
809
  }
2680
12.5k
2681
12.5k
  // If the type starts with '<', then it is either a packed struct or a vector.
2682
12.5k
  bool isPacked = EatIfPresent(lltok::less);
2683
12.5k
2684
12.5k
  // If we don't have a struct, then we have a random type alias, which we
2685
12.5k
  // accept for compatibility with old files.  These types are not allowed to be
2686
12.5k
  // forward referenced and not allowed to be recursive.
2687
12.5k
  if (Lex.getKind() != lltok::lbrace) {
2688
706
    if (Entry.first)
2689
0
      return Error(TypeLoc, "forward references to non-struct type");
2690
706
2691
706
    ResultTy = nullptr;
2692
706
    if (isPacked)
2693
624
      return ParseArrayVectorType(ResultTy, true);
2694
82
    return ParseType(ResultTy);
2695
82
  }
2696
11.8k
2697
11.8k
  // This type is being defined, so clear the location to indicate this.
2698
11.8k
  Entry.second = SMLoc();
2699
11.8k
2700
11.8k
  // If this type number has never been uttered, create it.
2701
11.8k
  if (!Entry.first)
2702
7.64k
    Entry.first = StructType::create(Context, Name);
2703
11.8k
2704
11.8k
  StructType *STy = cast<StructType>(Entry.first);
2705
11.8k
2706
11.8k
  SmallVector<Type*, 8> Body;
2707
11.8k
  if (ParseStructBody(Body) ||
2708
11.8k
      
(11.8k
isPacked11.8k
&&
ParseToken(lltok::greater, "expected '>' in packed struct")777
))
2709
1
    return true;
2710
11.8k
2711
11.8k
  STy->setBody(Body, isPacked);
2712
11.8k
  ResultTy = STy;
2713
11.8k
  return false;
2714
11.8k
}
2715
2716
/// ParseStructType: Handles packed and unpacked types.  </> parsed elsewhere.
2717
///   StructType
2718
///     ::= '{' '}'
2719
///     ::= '{' Type (',' Type)* '}'
2720
///     ::= '<' '{' '}' '>'
2721
///     ::= '<' '{' Type (',' Type)* '}' '>'
2722
53.3k
bool LLParser::ParseStructBody(SmallVectorImpl<Type*> &Body) {
2723
53.3k
  assert(Lex.getKind() == lltok::lbrace);
2724
53.3k
  Lex.Lex(); // Consume the '{'
2725
53.3k
2726
53.3k
  // Handle the empty struct.
2727
53.3k
  if (EatIfPresent(lltok::rbrace))
2728
756
    return false;
2729
52.5k
2730
52.5k
  LocTy EltTyLoc = Lex.getLoc();
2731
52.5k
  Type *Ty = nullptr;
2732
52.5k
  if (ParseType(Ty)) 
return true0
;
2733
52.5k
  Body.push_back(Ty);
2734
52.5k
2735
52.5k
  if (!StructType::isValidElementType(Ty))
2736
0
    return Error(EltTyLoc, "invalid element type for struct");
2737
52.5k
2738
160k
  
while (52.5k
EatIfPresent(lltok::comma)) {
2739
108k
    EltTyLoc = Lex.getLoc();
2740
108k
    if (ParseType(Ty)) 
return true1
;
2741
108k
2742
108k
    if (!StructType::isValidElementType(Ty))
2743
1
      return Error(EltTyLoc, "invalid element type for struct");
2744
108k
2745
108k
    Body.push_back(Ty);
2746
108k
  }
2747
52.5k
2748
52.5k
  
return ParseToken(lltok::rbrace, "expected '}' at end of struct")52.5k
;
2749
52.5k
}
2750
2751
/// ParseArrayVectorType - Parse an array or vector type, assuming the first
2752
/// token has already been consumed.
2753
///   Type
2754
///     ::= '[' APSINTVAL 'x' Types ']'
2755
///     ::= '<' APSINTVAL 'x' Types '>'
2756
///     ::= '<' 'vscale' 'x' APSINTVAL 'x' Types '>'
2757
1.70M
bool LLParser::ParseArrayVectorType(Type *&Result, bool isVector) {
2758
1.70M
  bool Scalable = false;
2759
1.70M
2760
1.70M
  if (isVector && 
Lex.getKind() == lltok::kw_vscale1.50M
) {
2761
6
    Lex.Lex(); // consume the 'vscale'
2762
6
    if (ParseToken(lltok::kw_x, "expected 'x' after vscale"))
2763
0
      return true;
2764
6
2765
6
    Scalable = true;
2766
6
  }
2767
1.70M
2768
1.70M
  if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned() ||
2769
1.70M
      Lex.getAPSIntVal().getBitWidth() > 64)
2770
0
    return TokError("expected number in address space");
2771
1.70M
2772
1.70M
  LocTy SizeLoc = Lex.getLoc();
2773
1.70M
  uint64_t Size = Lex.getAPSIntVal().getZExtValue();
2774
1.70M
  Lex.Lex();
2775
1.70M
2776
1.70M
  if (ParseToken(lltok::kw_x, "expected 'x' after element count"))
2777
0
      return true;
2778
1.70M
2779
1.70M
  LocTy TypeLoc = Lex.getLoc();
2780
1.70M
  Type *EltTy = nullptr;
2781
1.70M
  if (ParseType(EltTy)) 
return true1
;
2782
1.70M
2783
1.70M
  if (ParseToken(isVector ? 
lltok::greater1.50M
:
lltok::rsquare198k
,
2784
1.70M
                 "expected end of sequential type"))
2785
0
    return true;
2786
1.70M
2787
1.70M
  if (isVector) {
2788
1.50M
    if (Size == 0)
2789
0
      return Error(SizeLoc, "zero element vector is illegal");
2790
1.50M
    if ((unsigned)Size != Size)
2791
0
      return Error(SizeLoc, "size too large for vector");
2792
1.50M
    if (!VectorType::isValidElementType(EltTy))
2793
0
      return Error(TypeLoc, "invalid vector element type");
2794
1.50M
    Result = VectorType::get(EltTy, unsigned(Size), Scalable);
2795
1.50M
  } else {
2796
198k
    if (!ArrayType::isValidElementType(EltTy))
2797
2
      return Error(TypeLoc, "invalid array element type");
2798
198k
    Result = ArrayType::get(EltTy, Size);
2799
198k
  }
2800
1.70M
  
return false1.70M
;
2801
1.70M
}
2802
2803
//===----------------------------------------------------------------------===//
2804
// Function Semantic Analysis.
2805
//===----------------------------------------------------------------------===//
2806
2807
LLParser::PerFunctionState::PerFunctionState(LLParser &p, Function &f,
2808
                                             int functionNumber)
2809
297k
  : P(p), F(f), FunctionNumber(functionNumber) {
2810
297k
2811
297k
  // Insert unnamed arguments into the NumberedVals list.
2812
297k
  for (Argument &A : F.args())
2813
500k
    if (!A.hasName())
2814
6.63k
      NumberedVals.push_back(&A);
2815
297k
}
2816
2817
297k
LLParser::PerFunctionState::~PerFunctionState() {
2818
297k
  // If there were any forward referenced non-basicblock values, delete them.
2819
297k
2820
297k
  for (const auto &P : ForwardRefVals) {
2821
11
    if (isa<BasicBlock>(P.second.first))
2822
5
      continue;
2823
6
    P.second.first->replaceAllUsesWith(
2824
6
        UndefValue::get(P.second.first->getType()));
2825
6
    P.second.first->deleteValue();
2826
6
  }
2827
297k
2828
297k
  for (const auto &P : ForwardRefValIDs) {
2829
1
    if (isa<BasicBlock>(P.second.first))
2830
0
      continue;
2831
1
    P.second.first->replaceAllUsesWith(
2832
1
        UndefValue::get(P.second.first->getType()));
2833
1
    P.second.first->deleteValue();
2834
1
  }
2835
297k
}
2836
2837
297k
bool LLParser::PerFunctionState::FinishFunction() {
2838
297k
  if (!ForwardRefVals.empty())
2839
2
    return P.Error(ForwardRefVals.begin()->second.second,
2840
2
                   "use of undefined value '%" + ForwardRefVals.begin()->first +
2841
2
                   "'");
2842
297k
  if (!ForwardRefValIDs.empty())
2843
0
    return P.Error(ForwardRefValIDs.begin()->second.second,
2844
0
                   "use of undefined value '%" +
2845
0
                   Twine(ForwardRefValIDs.begin()->first) + "'");
2846
297k
  return false;
2847
297k
}
2848
2849
/// GetVal - Get a value with the specified name or ID, creating a
2850
/// forward reference record if needed.  This can return null if the value
2851
/// exists but does not have the right type.
2852
Value *LLParser::PerFunctionState::GetVal(const std::string &Name, Type *Ty,
2853
1.98M
                                          LocTy Loc, bool IsCall) {
2854
1.98M
  // Look this name up in the normal function symbol table.
2855
1.98M
  Value *Val = F.getValueSymbolTable()->lookup(Name);
2856
1.98M
2857
1.98M
  // If this is a forward reference for the value, see if we already created a
2858
1.98M
  // forward ref record.
2859
1.98M
  if (!Val) {
2860
215k
    auto I = ForwardRefVals.find(Name);
2861
215k
    if (I != ForwardRefVals.end())
2862
1.20k
      Val = I->second.first;
2863
215k
  }
2864
1.98M
2865
1.98M
  // If we have the value in the symbol table or fwd-ref table, return it.
2866
1.98M
  if (Val)
2867
1.76M
    return P.checkValidVariableType(Loc, "%" + Name, Ty, Val, IsCall);
2868
214k
2869
214k
  // Don't make placeholders with invalid type.
2870
214k
  if (!Ty->isFirstClassType()) {
2871
0
    P.Error(Loc, "invalid use of a non-first-class type");
2872
0
    return nullptr;
2873
0
  }
2874
214k
2875
214k
  // Otherwise, create a new forward reference for this value and remember it.
2876
214k
  Value *FwdVal;
2877
214k
  if (Ty->isLabelTy()) {
2878
196k
    FwdVal = BasicBlock::Create(F.getContext(), Name, &F);
2879
196k
  } else {
2880
17.9k
    FwdVal = new Argument(Ty, Name);
2881
17.9k
  }
2882
214k
2883
214k
  ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
2884
214k
  return FwdVal;
2885
214k
}
2886
2887
Value *LLParser::PerFunctionState::GetVal(unsigned ID, Type *Ty, LocTy Loc,
2888
481k
                                          bool IsCall) {
2889
481k
  // Look this name up in the normal function symbol table.
2890
481k
  Value *Val = ID < NumberedVals.size() ? 
NumberedVals[ID]276k
:
nullptr205k
;
2891
481k
2892
481k
  // If this is a forward reference for the value, see if we already created a
2893
481k
  // forward ref record.
2894
481k
  if (!Val) {
2895
205k
    auto I = ForwardRefValIDs.find(ID);
2896
205k
    if (I != ForwardRefValIDs.end())
2897
3.96k
      Val = I->second.first;
2898
205k
  }
2899
481k
2900
481k
  // If we have the value in the symbol table or fwd-ref table, return it.
2901
481k
  if (Val)
2902
280k
    return P.checkValidVariableType(Loc, "%" + Twine(ID), Ty, Val, IsCall);
2903
201k
2904
201k
  if (!Ty->isFirstClassType()) {
2905
0
    P.Error(Loc, "invalid use of a non-first-class type");
2906
0
    return nullptr;
2907
0
  }
2908
201k
2909
201k
  // Otherwise, create a new forward reference for this value and remember it.
2910
201k
  Value *FwdVal;
2911
201k
  if (Ty->isLabelTy()) {
2912
200k
    FwdVal = BasicBlock::Create(F.getContext(), "", &F);
2913
200k
  } else {
2914
1.19k
    FwdVal = new Argument(Ty);
2915
1.19k
  }
2916
201k
2917
201k
  ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
2918
201k
  return FwdVal;
2919
201k
}
2920
2921
/// SetInstName - After an instruction is parsed and inserted into its
2922
/// basic block, this installs its name.
2923
bool LLParser::PerFunctionState::SetInstName(int NameID,
2924
                                             const std::string &NameStr,
2925
1.74M
                                             LocTy NameLoc, Instruction *Inst) {
2926
1.74M
  // If this instruction has void type, it cannot have a name or ID specified.
2927
1.74M
  if (Inst->getType()->isVoidTy()) {
2928
599k
    if (NameID != -1 || !NameStr.empty())
2929
0
      return P.Error(NameLoc, "instructions returning void cannot have a name");
2930
599k
    return false;
2931
599k
  }
2932
1.14M
2933
1.14M
  // If this was a numbered instruction, verify that the instruction is the
2934
1.14M
  // expected value and resolve any forward references.
2935
1.14M
  if (NameStr.empty()) {
2936
252k
    // If neither a name nor an ID was specified, just use the next ID.
2937
252k
    if (NameID == -1)
2938
6.45k
      NameID = NumberedVals.size();
2939
252k
2940
252k
    if (unsigned(NameID) != NumberedVals.size())
2941
0
      return P.Error(NameLoc, "instruction expected to be numbered '%" +
2942
0
                     Twine(NumberedVals.size()) + "'");
2943
252k
2944
252k
    auto FI = ForwardRefValIDs.find(NameID);
2945
252k
    if (FI != ForwardRefValIDs.end()) {
2946
1.19k
      Value *Sentinel = FI->second.first;
2947
1.19k
      if (Sentinel->getType() != Inst->getType())
2948
0
        return P.Error(NameLoc, "instruction forward referenced with type '" +
2949
0
                       getTypeString(FI->second.first->getType()) + "'");
2950
1.19k
2951
1.19k
      Sentinel->replaceAllUsesWith(Inst);
2952
1.19k
      Sentinel->deleteValue();
2953
1.19k
      ForwardRefValIDs.erase(FI);
2954
1.19k
    }
2955
252k
2956
252k
    NumberedVals.push_back(Inst);
2957
252k
    return false;
2958
896k
  }
2959
896k
2960
896k
  // Otherwise, the instruction had a name.  Resolve forward refs and set it.
2961
896k
  auto FI = ForwardRefVals.find(NameStr);
2962
896k
  if (FI != ForwardRefVals.end()) {
2963
17.9k
    Value *Sentinel = FI->second.first;
2964
17.9k
    if (Sentinel->getType() != Inst->getType())
2965
0
      return P.Error(NameLoc, "instruction forward referenced with type '" +
2966
0
                     getTypeString(FI->second.first->getType()) + "'");
2967
17.9k
2968
17.9k
    Sentinel->replaceAllUsesWith(Inst);
2969
17.9k
    Sentinel->deleteValue();
2970
17.9k
    ForwardRefVals.erase(FI);
2971
17.9k
  }
2972
896k
2973
896k
  // Set the name on the instruction.
2974
896k
  Inst->setName(NameStr);
2975
896k
2976
896k
  if (Inst->getName() != NameStr)
2977
1
    return P.Error(NameLoc, "multiple definition of local value named '" +
2978
1
                   NameStr + "'");
2979
896k
  return false;
2980
896k
}
2981
2982
/// GetBB - Get a basic block with the specified name or ID, creating a
2983
/// forward reference record if needed.
2984
BasicBlock *LLParser::PerFunctionState::GetBB(const std::string &Name,
2985
196k
                                              LocTy Loc) {
2986
196k
  return dyn_cast_or_null<BasicBlock>(
2987
196k
      GetVal(Name, Type::getLabelTy(F.getContext()), Loc, /*IsCall=*/false));
2988
196k
}
2989
2990
200k
BasicBlock *LLParser::PerFunctionState::GetBB(unsigned ID, LocTy Loc) {
2991
200k
  return dyn_cast_or_null<BasicBlock>(
2992
200k
      GetVal(ID, Type::getLabelTy(F.getContext()), Loc, /*IsCall=*/false));
2993
200k
}
2994
2995
/// DefineBB - Define the specified basic block, which is either named or
2996
/// unnamed.  If there is an error, this returns null otherwise it returns
2997
/// the block being defined.
2998
BasicBlock *LLParser::PerFunctionState::DefineBB(const std::string &Name,
2999
396k
                                                 int NameID, LocTy Loc) {
3000
396k
  BasicBlock *BB;
3001
396k
  if (Name.empty()) {
3002
200k
    if (NameID != -1 && 
unsigned(NameID) != NumberedVals.size()236
) {
3003
1
      P.Error(Loc, "label expected to be numbered '" +
3004
1
                       Twine(NumberedVals.size()) + "'");
3005
1
      return nullptr;
3006
1
    }
3007
200k
    BB = GetBB(NumberedVals.size(), Loc);
3008
200k
    if (!BB) {
3009
0
      P.Error(Loc, "unable to create block numbered '" +
3010
0
                       Twine(NumberedVals.size()) + "'");
3011
0
      return nullptr;
3012
0
    }
3013
196k
  } else {
3014
196k
    BB = GetBB(Name, Loc);
3015
196k
    if (!BB) {
3016
1
      P.Error(Loc, "unable to create block named '" + Name + "'");
3017
1
      return nullptr;
3018
1
    }
3019
396k
  }
3020
396k
3021
396k
  // Move the block to the end of the function.  Forward ref'd blocks are
3022
396k
  // inserted wherever they happen to be referenced.
3023
396k
  F.getBasicBlockList().splice(F.end(), F.getBasicBlockList(), BB);
3024
396k
3025
396k
  // Remove the block from forward ref sets.
3026
396k
  if (Name.empty()) {
3027
200k
    ForwardRefValIDs.erase(NumberedVals.size());
3028
200k
    NumberedVals.push_back(BB);
3029
200k
  } else {
3030
196k
    // BB forward references are already in the function symbol table.
3031
196k
    ForwardRefVals.erase(Name);
3032
196k
  }
3033
396k
3034
396k
  return BB;
3035
396k
}
3036
3037
//===----------------------------------------------------------------------===//
3038
// Constants.
3039
//===----------------------------------------------------------------------===//
3040
3041
/// ParseValID - Parse an abstract value that doesn't necessarily have a
3042
/// type implied.  For example, if we parse "4" we don't know what integer type
3043
/// it has.  The value will later be combined with its type and checked for
3044
/// sanity.  PFS is used to convert function-local operands of metadata (since
3045
/// metadata operands are not just parsed here but also converted to values).
3046
/// PFS can be null when we are not parsing metadata values inside a function.
3047
4.38M
bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
3048
4.38M
  ID.Loc = Lex.getLoc();
3049
4.38M
  switch (Lex.getKind()) {
3050
4.38M
  
default: return TokError("expected value token")1
;
3051
4.38M
  case lltok::GlobalID:  // @42
3052
665
    ID.UIntVal = Lex.getUIntVal();
3053
665
    ID.Kind = ValID::t_GlobalID;
3054
665
    break;
3055
4.38M
  case lltok::GlobalVar:  // @foo
3056
298k
    ID.StrVal = Lex.getStrVal();
3057
298k
    ID.Kind = ValID::t_GlobalName;
3058
298k
    break;
3059
4.38M
  case lltok::LocalVarID:  // %42
3060
281k
    ID.UIntVal = Lex.getUIntVal();
3061
281k
    ID.Kind = ValID::t_LocalID;
3062
281k
    break;
3063
4.38M
  case lltok::LocalVar:  // %foo
3064
1.78M
    ID.StrVal = Lex.getStrVal();
3065
1.78M
    ID.Kind = ValID::t_LocalName;
3066
1.78M
    break;
3067
4.38M
  case lltok::APSInt:
3068
1.48M
    ID.APSIntVal = Lex.getAPSIntVal();
3069
1.48M
    ID.Kind = ValID::t_APSInt;
3070
1.48M
    break;
3071
4.38M
  case lltok::APFloat:
3072
67.1k
    ID.APFloatVal = Lex.getAPFloatVal();
3073
67.1k
    ID.Kind = ValID::t_APFloat;
3074
67.1k
    break;
3075
4.38M
  case lltok::kw_true:
3076
10.3k
    ID.ConstantVal = ConstantInt::getTrue(Context);
3077
10.3k
    ID.Kind = ValID::t_Constant;
3078
10.3k
    break;
3079
4.38M
  case lltok::kw_false:
3080
14.2k
    ID.ConstantVal = ConstantInt::getFalse(Context);
3081
14.2k
    ID.Kind = ValID::t_Constant;
3082
14.2k
    break;
3083
4.38M
  
case lltok::kw_null: ID.Kind = ValID::t_Null; break8.77k
;
3084
4.38M
  
case lltok::kw_undef: ID.Kind = ValID::t_Undef; break215k
;
3085
4.38M
  
case lltok::kw_zeroinitializer: ID.Kind = ValID::t_Zero; break33.5k
;
3086
4.38M
  
case lltok::kw_none: ID.Kind = ValID::t_None; break582
;
3087
4.38M
3088
4.38M
  case lltok::lbrace: {
3089
1.85k
    // ValID ::= '{' ConstVector '}'
3090
1.85k
    Lex.Lex();
3091
1.85k
    SmallVector<Constant*, 16> Elts;
3092
1.85k
    if (ParseGlobalValueVector(Elts) ||
3093
1.85k
        
ParseToken(lltok::rbrace, "expected end of struct constant")1.85k
)
3094
5
      return true;
3095
1.85k
3096
1.85k
    ID.ConstantStructElts = make_unique<Constant *[]>(Elts.size());
3097
1.85k
    ID.UIntVal = Elts.size();
3098
1.85k
    memcpy(ID.ConstantStructElts.get(), Elts.data(),
3099
1.85k
           Elts.size() * sizeof(Elts[0]));
3100
1.85k
    ID.Kind = ValID::t_ConstantStruct;
3101
1.85k
    return false;
3102
1.85k
  }
3103
91.5k
  case lltok::less: {
3104
91.5k
    // ValID ::= '<' ConstVector '>'         --> Vector.
3105
91.5k
    // ValID ::= '<' '{' ConstVector '}' '>' --> Packed Struct.
3106
91.5k
    Lex.Lex();
3107
91.5k
    bool isPackedStruct = EatIfPresent(lltok::lbrace);
3108
91.5k
3109
91.5k
    SmallVector<Constant*, 16> Elts;
3110
91.5k
    LocTy FirstEltLoc = Lex.getLoc();
3111
91.5k
    if (ParseGlobalValueVector(Elts) ||
3112
91.5k
        (isPackedStruct &&
3113
91.5k
         
ParseToken(lltok::rbrace, "expected end of packed struct")102
) ||
3114
91.5k
        ParseToken(lltok::greater, "expected end of constant"))
3115
0
      return true;
3116
91.5k
3117
91.5k
    if (isPackedStruct) {
3118
102
      ID.ConstantStructElts = make_unique<Constant *[]>(Elts.size());
3119
102
      memcpy(ID.ConstantStructElts.get(), Elts.data(),
3120
102
             Elts.size() * sizeof(Elts[0]));
3121
102
      ID.UIntVal = Elts.size();
3122
102
      ID.Kind = ValID::t_PackedConstantStruct;
3123
102
      return false;
3124
102
    }
3125
91.3k
3126
91.3k
    if (Elts.empty())
3127
0
      return Error(ID.Loc, "constant vector must not be empty");
3128
91.3k
3129
91.3k
    if (!Elts[0]->getType()->isIntegerTy() &&
3130
91.3k
        
!Elts[0]->getType()->isFloatingPointTy()8.17k
&&
3131
91.3k
        
!Elts[0]->getType()->isPointerTy()63
)
3132
0
      return Error(FirstEltLoc,
3133
0
            "vector elements must have integer, pointer or floating point type");
3134
91.3k
3135
91.3k
    // Verify that all the vector elements have the same type.
3136
1.05M
    
for (unsigned i = 1, e = Elts.size(); 91.3k
i != e;
++i964k
)
3137
964k
      if (Elts[i]->getType() != Elts[0]->getType())
3138
0
        return Error(FirstEltLoc,
3139
0
                     "vector element #" + Twine(i) +
3140
0
                    " is not of type '" + getTypeString(Elts[0]->getType()));
3141
91.3k
3142
91.3k
    ID.ConstantVal = ConstantVector::get(Elts);
3143
91.3k
    ID.Kind = ValID::t_Constant;
3144
91.3k
    return false;
3145
91.3k
  }
3146
91.3k
  case lltok::lsquare: {   // Array Constant
3147
1.59k
    Lex.Lex();
3148
1.59k
    SmallVector<Constant*, 16> Elts;
3149
1.59k
    LocTy FirstEltLoc = Lex.getLoc();
3150
1.59k
    if (ParseGlobalValueVector(Elts) ||
3151
1.59k
        ParseToken(lltok::rsquare, "expected end of array constant"))
3152
0
      return true;
3153
1.59k
3154
1.59k
    // Handle empty element.
3155
1.59k
    if (Elts.empty()) {
3156
19
      // Use undef instead of an array because it's inconvenient to determine
3157
19
      // the element type at this point, there being no elements to examine.
3158
19
      ID.Kind = ValID::t_EmptyArray;
3159
19
      return false;
3160
19
    }
3161
1.57k
3162
1.57k
    if (!Elts[0]->getType()->isFirstClassType())
3163
0
      return Error(FirstEltLoc, "invalid array element type: " +
3164
0
                   getTypeString(Elts[0]->getType()));
3165
1.57k
3166
1.57k
    ArrayType *ATy = ArrayType::get(Elts[0]->getType(), Elts.size());
3167
1.57k
3168
1.57k
    // Verify all elements are correct type!
3169
7.49k
    for (unsigned i = 0, e = Elts.size(); i != e; 
++i5.92k
) {
3170
5.92k
      if (Elts[i]->getType() != Elts[0]->getType())
3171
0
        return Error(FirstEltLoc,
3172
0
                     "array element #" + Twine(i) +
3173
0
                     " is not of type '" + getTypeString(Elts[0]->getType()));
3174
5.92k
    }
3175
1.57k
3176
1.57k
    ID.ConstantVal = ConstantArray::get(ATy, Elts);
3177
1.57k
    ID.Kind = ValID::t_Constant;
3178
1.57k
    return false;
3179
1.57k
  }
3180
2.23k
  case lltok::kw_c:  // c "foo"
3181
2.23k
    Lex.Lex();
3182
2.23k
    ID.ConstantVal = ConstantDataArray::getString(Context, Lex.getStrVal(),
3183
2.23k
                                                  false);
3184
2.23k
    if (ParseToken(lltok::StringConstant, "expected string")) 
return true0
;
3185
2.23k
    ID.Kind = ValID::t_Constant;
3186
2.23k
    return false;
3187
2.23k
3188
10.5k
  case lltok::kw_asm: {
3189
10.5k
    // ValID ::= 'asm' SideEffect? AlignStack? IntelDialect? STRINGCONSTANT ','
3190
10.5k
    //             STRINGCONSTANT
3191
10.5k
    bool HasSideEffect, AlignStack, AsmDialect;
3192
10.5k
    Lex.Lex();
3193
10.5k
    if (ParseOptionalToken(lltok::kw_sideeffect, HasSideEffect) ||
3194
10.5k
        ParseOptionalToken(lltok::kw_alignstack, AlignStack) ||
3195
10.5k
        ParseOptionalToken(lltok::kw_inteldialect, AsmDialect) ||
3196
10.5k
        ParseStringConstant(ID.StrVal) ||
3197
10.5k
        ParseToken(lltok::comma, "expected comma in inline asm expression") ||
3198
10.5k
        ParseToken(lltok::StringConstant, "expected constraint string"))
3199
0
      return true;
3200
10.5k
    ID.StrVal2 = Lex.getStrVal();
3201
10.5k
    ID.UIntVal = unsigned(HasSideEffect) | (unsigned(AlignStack)<<1) |
3202
10.5k
      (unsigned(AsmDialect)<<2);
3203
10.5k
    ID.Kind = ValID::t_InlineAsm;
3204
10.5k
    return false;
3205
10.5k
  }
3206
10.5k
3207
10.5k
  case lltok::kw_blockaddress: {
3208
768
    // ValID ::= 'blockaddress' '(' @foo ',' %bar ')'
3209
768
    Lex.Lex();
3210
768
3211
768
    ValID Fn, Label;
3212
768
3213
768
    if (ParseToken(lltok::lparen, "expected '(' in block address expression") ||
3214
768
        ParseValID(Fn) ||
3215
768
        ParseToken(lltok::comma, "expected comma in block address expression")||
3216
768
        ParseValID(Label) ||
3217
768
        ParseToken(lltok::rparen, "expected ')' in block address expression"))
3218
0
      return true;
3219
768
3220
768
    if (Fn.Kind != ValID::t_GlobalID && Fn.Kind != ValID::t_GlobalName)
3221
0
      return Error(Fn.Loc, "expected function name in blockaddress");
3222
768
    if (Label.Kind != ValID::t_LocalID && 
Label.Kind != ValID::t_LocalName732
)
3223
0
      return Error(Label.Loc, "expected basic block name in blockaddress");
3224
768
3225
768
    // Try to find the function (but skip it if it's forward-referenced).
3226
768
    GlobalValue *GV = nullptr;
3227
768
    if (Fn.Kind == ValID::t_GlobalID) {
3228
0
      if (Fn.UIntVal < NumberedVals.size())
3229
0
        GV = NumberedVals[Fn.UIntVal];
3230
768
    } else if (!ForwardRefVals.count(Fn.StrVal)) {
3231
768
      GV = M->getNamedValue(Fn.StrVal);
3232
768
    }
3233
768
    Function *F = nullptr;
3234
768
    if (GV) {
3235
384
      // Confirm that it's actually a function with a definition.
3236
384
      if (!isa<Function>(GV))
3237
0
        return Error(Fn.Loc, "expected function name in blockaddress");
3238
384
      F = cast<Function>(GV);
3239
384
      if (F->isDeclaration())
3240
0
        return Error(Fn.Loc, "cannot take blockaddress inside a declaration");
3241
768
    }
3242
768
3243
768
    if (!F) {
3244
384
      // Make a global variable as a placeholder for this reference.
3245
384
      GlobalValue *&FwdRef =
3246
384
          ForwardRefBlockAddresses.insert(std::make_pair(
3247
384
                                              std::move(Fn),
3248
384
                                              std::map<ValID, GlobalValue *>()))
3249
384
              .first->second.insert(std::make_pair(std::move(Label), nullptr))
3250
384
              .first->second;
3251
384
      if (!FwdRef)
3252
332
        FwdRef = new GlobalVariable(*M, Type::getInt8Ty(Context), false,
3253
332
                                    GlobalValue::InternalLinkage, nullptr, "");
3254
384
      ID.ConstantVal = FwdRef;
3255
384
      ID.Kind = ValID::t_Constant;
3256
384
      return false;
3257
384
    }
3258
384
3259
384
    // We found the function; now find the basic block.  Don't use PFS, since we
3260
384
    // might be inside a constant expression.
3261
384
    BasicBlock *BB;
3262
384
    if (BlockAddressPFS && 
F == &BlockAddressPFS->getFunction()382
) {
3263
307
      if (Label.Kind == ValID::t_LocalID)
3264
18
        BB = BlockAddressPFS->GetBB(Label.UIntVal, Label.Loc);
3265
289
      else
3266
289
        BB = BlockAddressPFS->GetBB(Label.StrVal, Label.Loc);
3267
307
      if (!BB)
3268
0
        return Error(Label.Loc, "referenced value is not a basic block");
3269
77
    } else {
3270
77
      if (Label.Kind == ValID::t_LocalID)
3271
0
        return Error(Label.Loc, "cannot take address of numeric label after "
3272
0
                                "the function is defined");
3273
77
      BB = dyn_cast_or_null<BasicBlock>(
3274
77
          F->getValueSymbolTable()->lookup(Label.StrVal));
3275
77
      if (!BB)
3276
0
        return Error(Label.Loc, "referenced value is not a basic block");
3277
384
    }
3278
384
3279
384
    ID.ConstantVal = BlockAddress::get(F, BB);
3280
384
    ID.Kind = ValID::t_Constant;
3281
384
    return false;
3282
384
  }
3283
384
3284
9.58k
  case lltok::kw_trunc:
3285
9.58k
  case lltok::kw_zext:
3286
9.58k
  case lltok::kw_sext:
3287
9.58k
  case lltok::kw_fptrunc:
3288
9.58k
  case lltok::kw_fpext:
3289
9.58k
  case lltok::kw_bitcast:
3290
9.58k
  case lltok::kw_addrspacecast:
3291
9.58k
  case lltok::kw_uitofp:
3292
9.58k
  case lltok::kw_sitofp:
3293
9.58k
  case lltok::kw_fptoui:
3294
9.58k
  case lltok::kw_fptosi:
3295
9.58k
  case lltok::kw_inttoptr:
3296
9.58k
  case lltok::kw_ptrtoint: {
3297
9.58k
    unsigned Opc = Lex.getUIntVal();
3298
9.58k
    Type *DestTy = nullptr;
3299
9.58k
    Constant *SrcVal;
3300
9.58k
    Lex.Lex();
3301
9.58k
    if (ParseToken(lltok::lparen, "expected '(' after constantexpr cast") ||
3302
9.58k
        ParseGlobalTypeAndValue(SrcVal) ||
3303
9.58k
        
ParseToken(lltok::kw_to, "expected 'to' in constantexpr cast")9.57k
||
3304
9.58k
        
ParseType(DestTy)9.57k
||
3305
9.58k
        
ParseToken(lltok::rparen, "expected ')' at end of constantexpr cast")9.57k
)
3306
1
      return true;
3307
9.57k
    if (!CastInst::castIsValid((Instruction::CastOps)Opc, SrcVal, DestTy))
3308
10
      return Error(ID.Loc, "invalid cast opcode for cast from '" +
3309
10
                   getTypeString(SrcVal->getType()) + "' to '" +
3310
10
                   getTypeString(DestTy) + "'");
3311
9.56k
    ID.ConstantVal = ConstantExpr::getCast((Instruction::CastOps)Opc,
3312
9.56k
                                                 SrcVal, DestTy);
3313
9.56k
    ID.Kind = ValID::t_Constant;
3314
9.56k
    return false;
3315
9.56k
  }
3316
9.56k
  case lltok::kw_extractvalue: {
3317
11
    Lex.Lex();
3318
11
    Constant *Val;
3319
11
    SmallVector<unsigned, 4> Indices;
3320
11
    if (ParseToken(lltok::lparen, "expected '(' in extractvalue constantexpr")||
3321
11
        ParseGlobalTypeAndValue(Val) ||
3322
11
        ParseIndexList(Indices) ||
3323
11
        ParseToken(lltok::rparen, "expected ')' in extractvalue constantexpr"))
3324
0
      return true;
3325
11
3326
11
    if (!Val->getType()->isAggregateType())
3327
0
      return Error(ID.Loc, "extractvalue operand must be aggregate type");
3328
11
    if (!ExtractValueInst::getIndexedType(Val->getType(), Indices))
3329
0
      return Error(ID.Loc, "invalid indices for extractvalue");
3330
11
    ID.ConstantVal = ConstantExpr::getExtractValue(Val, Indices);
3331
11
    ID.Kind = ValID::t_Constant;
3332
11
    return false;
3333
11
  }
3334
11
  case lltok::kw_insertvalue: {
3335
10
    Lex.Lex();
3336
10
    Constant *Val0, *Val1;
3337
10
    SmallVector<unsigned, 4> Indices;
3338
10
    if (ParseToken(lltok::lparen, "expected '(' in insertvalue constantexpr")||
3339
10
        ParseGlobalTypeAndValue(Val0) ||
3340
10
        ParseToken(lltok::comma, "expected comma in insertvalue constantexpr")||
3341
10
        ParseGlobalTypeAndValue(Val1) ||
3342
10
        ParseIndexList(Indices) ||
3343
10
        ParseToken(lltok::rparen, "expected ')' in insertvalue constantexpr"))
3344
0
      return true;
3345
10
    if (!Val0->getType()->isAggregateType())
3346
0
      return Error(ID.Loc, "insertvalue operand must be aggregate type");
3347
10
    Type *IndexedType =
3348
10
        ExtractValueInst::getIndexedType(Val0->getType(), Indices);
3349
10
    if (!IndexedType)
3350
0
      return Error(ID.Loc, "invalid indices for insertvalue");
3351
10
    if (IndexedType != Val1->getType())
3352
1
      return Error(ID.Loc, "insertvalue operand and field disagree in type: '" +
3353
1
                               getTypeString(Val1->getType()) +
3354
1
                               "' instead of '" + getTypeString(IndexedType) +
3355
1
                               "'");
3356
9
    ID.ConstantVal = ConstantExpr::getInsertValue(Val0, Val1, Indices);
3357
9
    ID.Kind = ValID::t_Constant;
3358
9
    return false;
3359
9
  }
3360
312
  case lltok::kw_icmp:
3361
312
  case lltok::kw_fcmp: {
3362
312
    unsigned PredVal, Opc = Lex.getUIntVal();
3363
312
    Constant *Val0, *Val1;
3364
312
    Lex.Lex();
3365
312
    if (ParseCmpPredicate(PredVal, Opc) ||
3366
312
        ParseToken(lltok::lparen, "expected '(' in compare constantexpr") ||
3367
312
        ParseGlobalTypeAndValue(Val0) ||
3368
312
        ParseToken(lltok::comma, "expected comma in compare constantexpr") ||
3369
312
        ParseGlobalTypeAndValue(Val1) ||
3370
312
        ParseToken(lltok::rparen, "expected ')' in compare constantexpr"))
3371
0
      return true;
3372
312
3373
312
    if (Val0->getType() != Val1->getType())
3374
0
      return Error(ID.Loc, "compare operands must have the same type");
3375
312
3376
312
    CmpInst::Predicate Pred = (CmpInst::Predicate)PredVal;
3377
312
3378
312
    if (Opc == Instruction::FCmp) {
3379
6
      if (!Val0->getType()->isFPOrFPVectorTy())
3380
0
        return Error(ID.Loc, "fcmp requires floating point operands");
3381
6
      ID.ConstantVal = ConstantExpr::getFCmp(Pred, Val0, Val1);
3382
306
    } else {
3383
306
      assert(Opc == Instruction::ICmp && "Unexpected opcode for CmpInst!");
3384
306
      if (!Val0->getType()->isIntOrIntVectorTy() &&
3385
306
          
!Val0->getType()->isPtrOrPtrVectorTy()220
)
3386
0
        return Error(ID.Loc, "icmp requires pointer or integer operands");
3387
306
      ID.ConstantVal = ConstantExpr::getICmp(Pred, Val0, Val1);
3388
306
    }
3389
312
    ID.Kind = ValID::t_Constant;
3390
312
    return false;
3391
312
  }
3392
312
 
3393
312
  // Unary Operators.
3394
312
  case lltok::kw_fneg: {
3395
4
    unsigned Opc = Lex.getUIntVal();
3396
4
    Constant *Val;
3397
4
    Lex.Lex();
3398
4
    if (ParseToken(lltok::lparen, "expected '(' in unary constantexpr") ||
3399
4
        ParseGlobalTypeAndValue(Val) ||
3400
4
        ParseToken(lltok::rparen, "expected ')' in unary constantexpr"))
3401
0
      return true;
3402
4
    
3403
4
    // Check that the type is valid for the operator.
3404
4
    switch (Opc) {
3405
4
    case Instruction::FNeg:
3406
4
      if (!Val->getType()->isFPOrFPVectorTy())
3407
0
        return Error(ID.Loc, "constexpr requires fp operands");
3408
4
      break;
3409
4
    
default: 0
llvm_unreachable0
("Unknown unary operator!");
3410
4
    }
3411
4
    unsigned Flags = 0;
3412
4
    Constant *C = ConstantExpr::get(Opc, Val, Flags);
3413
4
    ID.ConstantVal = C;
3414
4
    ID.Kind = ValID::t_Constant;
3415
4
    return false;
3416
4
  }
3417
4
  // Binary Operators.
3418
729
  case lltok::kw_add:
3419
729
  case lltok::kw_fadd:
3420
729
  case lltok::kw_sub:
3421
729
  case lltok::kw_fsub:
3422
729
  case lltok::kw_mul:
3423
729
  case lltok::kw_fmul:
3424
729
  case lltok::kw_udiv:
3425
729
  case lltok::kw_sdiv:
3426
729
  case lltok::kw_fdiv:
3427
729
  case lltok::kw_urem:
3428
729
  case lltok::kw_srem:
3429
729
  case lltok::kw_frem:
3430
729
  case lltok::kw_shl:
3431
729
  case lltok::kw_lshr:
3432
729
  case lltok::kw_ashr: {
3433
729
    bool NUW = false;
3434
729
    bool NSW = false;
3435
729
    bool Exact = false;
3436
729
    unsigned Opc = Lex.getUIntVal();
3437
729
    Constant *Val0, *Val1;
3438
729
    Lex.Lex();
3439
729
    if (Opc == Instruction::Add || 
Opc == Instruction::Sub629
||
3440
729
        
Opc == Instruction::Mul268
||
Opc == Instruction::Shl197
) {
3441
579
      if (EatIfPresent(lltok::kw_nuw))
3442
240
        NUW = true;
3443
579
      if (EatIfPresent(lltok::kw_nsw)) {
3444
259
        NSW = true;
3445
259
        if (EatIfPresent(lltok::kw_nuw))
3446
10
          NUW = true;
3447
259
      }
3448
579
    } else 
if (150
Opc == Instruction::SDiv150
||
Opc == Instruction::UDiv124
||
3449
150
               
Opc == Instruction::LShr114
||
Opc == Instruction::AShr58
) {
3450
117
      if (EatIfPresent(lltok::kw_exact))
3451
24
        Exact = true;
3452
117
    }
3453
729
    if (ParseToken(lltok::lparen, "expected '(' in binary constantexpr") ||
3454
729
        ParseGlobalTypeAndValue(Val0) ||
3455
729
        ParseToken(lltok::comma, "expected comma in binary constantexpr") ||
3456
729
        ParseGlobalTypeAndValue(Val1) ||
3457
729
        ParseToken(lltok::rparen, "expected ')' in binary constantexpr"))
3458
0
      return true;
3459
729
    if (Val0->getType() != Val1->getType())
3460
0
      return Error(ID.Loc, "operands of constexpr must have same type");
3461
729
    // Check that the type is valid for the operator.
3462
729
    switch (Opc) {
3463
729
    case Instruction::Add:
3464
707
    case Instruction::Sub:
3465
707
    case Instruction::Mul:
3466
707
    case Instruction::UDiv:
3467
707
    case Instruction::SDiv:
3468
707
    case Instruction::URem:
3469
707
    case Instruction::SRem:
3470
707
    case Instruction::Shl:
3471
707
    case Instruction::AShr:
3472
707
    case Instruction::LShr:
3473
707
      if (!Val0->getType()->isIntOrIntVectorTy())
3474
1
        return Error(ID.Loc, "constexpr requires integer operands");
3475
706
      break;
3476
706
    case Instruction::FAdd:
3477
22
    case Instruction::FSub:
3478
22
    case Instruction::FMul:
3479
22
    case Instruction::FDiv:
3480
22
    case Instruction::FRem:
3481
22
      if (!Val0->getType()->isFPOrFPVectorTy())
3482
0
        return Error(ID.Loc, "constexpr requires fp operands");
3483
22
      break;
3484
22
    
default: 0
llvm_unreachable0
("Unknown binary operator!");
3485
728
    }
3486
728
    unsigned Flags = 0;
3487
728
    if (NUW)   
Flags |= OverflowingBinaryOperator::NoUnsignedWrap250
;
3488
728
    if (NSW)   
Flags |= OverflowingBinaryOperator::NoSignedWrap259
;
3489
728
    if (Exact) 
Flags |= PossiblyExactOperator::IsExact24
;
3490
728
    Constant *C = ConstantExpr::get(Opc, Val0, Val1, Flags);
3491
728
    ID.ConstantVal = C;
3492
728
    ID.Kind = ValID::t_Constant;
3493
728
    return false;
3494
728
  }
3495
728
3496
728
  // Logical Operations
3497
728
  case lltok::kw_and:
3498
114
  case lltok::kw_or:
3499
114
  case lltok::kw_xor: {
3500
114
    unsigned Opc = Lex.getUIntVal();
3501
114
    Constant *Val0, *Val1;
3502
114
    Lex.Lex();
3503
114
    if (ParseToken(lltok::lparen, "expected '(' in logical constantexpr") ||
3504
114
        ParseGlobalTypeAndValue(Val0) ||
3505
114
        ParseToken(lltok::comma, "expected comma in logical constantexpr") ||
3506
114
        ParseGlobalTypeAndValue(Val1) ||
3507
114
        ParseToken(lltok::rparen, "expected ')' in logical constantexpr"))
3508
0
      return true;
3509
114
    if (Val0->getType() != Val1->getType())
3510
0
      return Error(ID.Loc, "operands of constexpr must have same type");
3511
114
    if (!Val0->getType()->isIntOrIntVectorTy())
3512
0
      return Error(ID.Loc,
3513
0
                   "constexpr requires integer or integer vector operands");
3514
114
    ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1);
3515
114
    ID.Kind = ValID::t_Constant;
3516
114
    return false;
3517
114
  }
3518
114
3519
71.1k
  case lltok::kw_getelementptr:
3520
71.1k
  case lltok::kw_shufflevector:
3521
71.1k
  case lltok::kw_insertelement:
3522
71.1k
  case lltok::kw_extractelement:
3523
71.1k
  case lltok::kw_select: {
3524
71.1k
    unsigned Opc = Lex.getUIntVal();
3525
71.1k
    SmallVector<Constant*, 16> Elts;
3526
71.1k
    bool InBounds = false;
3527
71.1k
    Type *Ty;
3528
71.1k
    Lex.Lex();
3529
71.1k
3530
71.1k
    if (Opc == Instruction::GetElementPtr)
3531
71.0k
      InBounds = EatIfPresent(lltok::kw_inbounds);
3532
71.1k
3533
71.1k
    if (ParseToken(lltok::lparen, "expected '(' in constantexpr"))
3534
0
      return true;
3535
71.1k
3536
71.1k
    LocTy ExplicitTypeLoc = Lex.getLoc();
3537
71.1k
    if (Opc == Instruction::GetElementPtr) {
3538
71.0k
      if (ParseType(Ty) ||
3539
71.0k
          ParseToken(lltok::comma, "expected comma after getelementptr's type"))
3540
0
        return true;
3541
71.1k
    }
3542
71.1k
3543
71.1k
    Optional<unsigned> InRangeOp;
3544
71.1k
    if (ParseGlobalValueVector(
3545
71.1k
            Elts, Opc == Instruction::GetElementPtr ? 
&InRangeOp71.0k
:
nullptr92
) ||
3546
71.1k
        
ParseToken(lltok::rparen, "expected ')' in constantexpr")71.1k
)
3547
1
      return true;
3548
71.1k
3549
71.1k
    if (Opc == Instruction::GetElementPtr) {
3550
71.0k
      if (Elts.size() == 0 ||
3551
71.0k
          !Elts[0]->getType()->isPtrOrPtrVectorTy())
3552
0
        return Error(ID.Loc, "base of getelementptr must be a pointer");
3553
71.0k
3554
71.0k
      Type *BaseType = Elts[0]->getType();
3555
71.0k
      auto *BasePointerType = cast<PointerType>(BaseType->getScalarType());
3556
71.0k
      if (Ty != BasePointerType->getElementType())
3557
0
        return Error(
3558
0
            ExplicitTypeLoc,
3559
0
            "explicit pointee type doesn't match operand's pointee type");
3560
71.0k
3561
71.0k
      unsigned GEPWidth =
3562
71.0k
          BaseType->isVectorTy() ? 
BaseType->getVectorNumElements()17
:
071.0k
;
3563
71.0k
3564
71.0k
      ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
3565
142k
      for (Constant *Val : Indices) {
3566
142k
        Type *ValTy = Val->getType();
3567
142k
        if (!ValTy->isIntOrIntVectorTy())
3568
0
          return Error(ID.Loc, "getelementptr index must be an integer");
3569
142k
        if (ValTy->isVectorTy()) {
3570
38
          unsigned ValNumEl = ValTy->getVectorNumElements();
3571
38
          if (GEPWidth && 
(ValNumEl != GEPWidth)36
)
3572
2
            return Error(
3573
2
                ID.Loc,
3574
2
                "getelementptr vector index has a wrong number of elements");
3575
36
          // GEPWidth may have been unknown because the base is a scalar,
3576
36
          // but it is known now.
3577
36
          GEPWidth = ValNumEl;
3578
36
        }
3579
142k
      }
3580
71.0k
3581
71.0k
      SmallPtrSet<Type*, 4> Visited;
3582
71.0k
      if (!Indices.empty() && 
!Ty->isSized(&Visited)71.0k
)
3583
0
        return Error(ID.Loc, "base element of getelementptr must be sized");
3584
71.0k
3585
71.0k
      if (!GetElementPtrInst::getIndexedType(Ty, Indices))
3586
0
        return Error(ID.Loc, "invalid getelementptr indices");
3587
71.0k
3588
71.0k
      if (InRangeOp) {
3589
72
        if (*InRangeOp == 0)
3590
0
          return Error(ID.Loc,
3591
0
                       "inrange keyword may not appear on pointer operand");
3592
72
        --*InRangeOp;
3593
72
      }
3594
71.0k
3595
71.0k
      ID.ConstantVal = ConstantExpr::getGetElementPtr(Ty, Elts[0], Indices,
3596
71.0k
                                                      InBounds, InRangeOp);
3597
71.0k
    } else 
if (92
Opc == Instruction::Select92
) {
3598
57
      if (Elts.size() != 3)
3599
0
        return Error(ID.Loc, "expected three operands to select");
3600
57
      if (const char *Reason = SelectInst::areInvalidOperands(Elts[0], Elts[1],
3601
0
                                                              Elts[2]))
3602
0
        return Error(ID.Loc, Reason);
3603
57
      ID.ConstantVal = ConstantExpr::getSelect(Elts[0], Elts[1], Elts[2]);
3604
57
    } else 
if (35
Opc == Instruction::ShuffleVector35
) {
3605
10
      if (Elts.size() != 3)
3606
0
        return Error(ID.Loc, "expected three operands to shufflevector");
3607
10
      if (!ShuffleVectorInst::isValidOperands(Elts[0], Elts[1], Elts[2]))
3608
0
        return Error(ID.Loc, "invalid operands to shufflevector");
3609
10
      ID.ConstantVal =
3610
10
                 ConstantExpr::getShuffleVector(Elts[0], Elts[1],Elts[2]);
3611
25
    } else if (Opc == Instruction::ExtractElement) {
3612
23
      if (Elts.size() != 2)
3613
0
        return Error(ID.Loc, "expected two operands to extractelement");
3614
23
      if (!ExtractElementInst::isValidOperands(Elts[0], Elts[1]))
3615
0
        return Error(ID.Loc, "invalid extractelement operands");
3616
23
      ID.ConstantVal = ConstantExpr::getExtractElement(Elts[0], Elts[1]);
3617
23
    } else {
3618
2
      assert(Opc == Instruction::InsertElement && "Unknown opcode");
3619
2
      if (Elts.size() != 3)
3620
0
      return Error(ID.Loc, "expected three operands to insertelement");
3621
2
      if (!InsertElementInst::isValidOperands(Elts[0], Elts[1], Elts[2]))
3622
0
        return Error(ID.Loc, "invalid insertelement operands");
3623
2
      ID.ConstantVal =
3624
2
                 ConstantExpr::getInsertElement(Elts[0], Elts[1],Elts[2]);
3625
2
    }
3626
71.1k
3627
71.1k
    ID.Kind = ValID::t_Constant;
3628
71.1k
    return false;
3629
4.19M
  }
3630
4.19M
  }
3631
4.19M
3632
4.19M
  Lex.Lex();
3633
4.19M
  return false;
3634
4.19M
}
3635
3636
/// ParseGlobalValue - Parse a global value with the specified type.
3637
1.31M
bool LLParser::ParseGlobalValue(Type *Ty, Constant *&C) {
3638
1.31M
  C = nullptr;
3639
1.31M
  ValID ID;
3640
1.31M
  Value *V = nullptr;
3641
1.31M
  bool Parsed = ParseValID(ID) ||
3642
1.31M
                
ConvertValIDToValue(Ty, ID, V, nullptr, /*IsCall=*/false)1.31M
;
3643
1.31M
  if (V && 
!(C = dyn_cast<Constant>(V))1.31M
)
3644
0
    return Error(ID.Loc, "global values must be constants");
3645
1.31M
  return Parsed;
3646
1.31M
}
3647
3648
1.29M
bool LLParser::ParseGlobalTypeAndValue(Constant *&V) {
3649
1.29M
  Type *Ty = nullptr;
3650
1.29M
  return ParseType(Ty) ||
3651
1.29M
         ParseGlobalValue(Ty, V);
3652
1.29M
}
3653
3654
379k
bool LLParser::parseOptionalComdat(StringRef GlobalName, Comdat *&C) {
3655
379k
  C = nullptr;
3656
379k
3657
379k
  LocTy KwLoc = Lex.getLoc();
3658
379k
  if (!EatIfPresent(lltok::kw_comdat))
3659
378k
    return false;
3660
907
3661
907
  if (EatIfPresent(lltok::lparen)) {
3662
318
    if (Lex.getKind() != lltok::ComdatVar)
3663
0
      return TokError("expected comdat variable");
3664
318
    C = getComdat(Lex.getStrVal(), Lex.getLoc());
3665
318
    Lex.Lex();
3666
318
    if (ParseToken(lltok::rparen, "expected ')' after comdat var"))
3667
0
      return true;
3668
589
  } else {
3669
589
    if (GlobalName.empty())
3670
1
      return TokError("comdat cannot be unnamed");
3671
588
    C = getComdat(GlobalName, KwLoc);
3672
588
  }
3673
907
3674
907
  
return false906
;
3675
907
}
3676
3677
/// ParseGlobalValueVector
3678
///   ::= /*empty*/
3679
///   ::= [inrange] TypeAndValue (',' [inrange] TypeAndValue)*
3680
bool LLParser::ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
3681
166k
                                      Optional<unsigned> *InRangeOp) {
3682
166k
  // Empty list.
3683
166k
  if (Lex.getKind() == lltok::rbrace ||
3684
166k
      
Lex.getKind() == lltok::rsquare166k
||
3685
166k
      
Lex.getKind() == lltok::greater166k
||
3686
166k
      
Lex.getKind() == lltok::rparen166k
)
3687
29
    return false;
3688
166k
3689
1.28M
  
do 166k
{
3690
1.28M
    if (InRangeOp && 
!*InRangeOp213k
&&
EatIfPresent(lltok::kw_inrange)213k
)
3691
72
      *InRangeOp = Elts.size();
3692
1.28M
3693
1.28M
    Constant *C;
3694
1.28M
    if (ParseGlobalTypeAndValue(C)) 
return true6
;
3695
1.28M
    Elts.push_back(C);
3696
1.28M
  } while (EatIfPresent(lltok::comma));
3697
166k
3698
166k
  
return false166k
;
3699
166k
}
3700
3701
24.8k
bool LLParser::ParseMDTuple(MDNode *&MD, bool IsDistinct) {
3702
24.8k
  SmallVector<Metadata *, 16> Elts;
3703
24.8k
  if (ParseMDNodeVector(Elts))
3704
8
    return true;
3705
24.8k
3706
24.8k
  MD = (IsDistinct ? 
MDTuple::getDistinct737
:
MDTuple::get24.1k
)(Context, Elts);
3707
24.8k
  return false;
3708
24.8k
}
3709
3710
/// MDNode:
3711
///  ::= !{ ... }
3712
///  ::= !7
3713
///  ::= !DILocation(...)
3714
42.1k
bool LLParser::ParseMDNode(MDNode *&N) {
3715
42.1k
  if (Lex.getKind() == lltok::MetadataVar)
3716
96
    return ParseSpecializedMDNode(N);
3717
42.0k
3718
42.0k
  return ParseToken(lltok::exclaim, "expected '!' here") ||
3719
42.0k
         ParseMDNodeTail(N);
3720
42.0k
}
3721
3722
142k
bool LLParser::ParseMDNodeTail(MDNode *&N) {
3723
142k
  // !{ ... }
3724
142k
  if (Lex.getKind() == lltok::lbrace)
3725
456
    return ParseMDTuple(N);
3726
141k
3727
141k
  // !42
3728
141k
  return ParseMDNodeID(N);
3729
141k
}
3730
3731
namespace {
3732
3733
/// Structure to represent an optional metadata field.
3734
template <class FieldTy> struct MDFieldImpl {
3735
  typedef MDFieldImpl ImplTy;
3736
  FieldTy Val;
3737
  bool Seen;
3738
3739
188k
  void assign(FieldTy Val) {
3740
188k
    Seen = true;
3741
188k
    this->Val = std::move(Val);
3742
188k
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<unsigned long long>::assign(unsigned long long)
Line
Count
Source
3739
70.4k
  void assign(FieldTy Val) {
3740
70.4k
    Seen = true;
3741
70.4k
    this->Val = std::move(Val);
3742
70.4k
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::Metadata*>::assign(llvm::Metadata*)
Line
Count
Source
3739
64.2k
  void assign(FieldTy Val) {
3740
64.2k
    Seen = true;
3741
64.2k
    this->Val = std::move(Val);
3742
64.2k
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<bool>::assign(bool)
Line
Count
Source
3739
14.2k
  void assign(FieldTy Val) {
3740
14.2k
    Seen = true;
3741
14.2k
    this->Val = std::move(Val);
3742
14.2k
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::MDString*>::assign(llvm::MDString*)
Line
Count
Source
3739
35.2k
  void assign(FieldTy Val) {
3740
35.2k
    Seen = true;
3741
35.2k
    this->Val = std::move(Val);
3742
35.2k
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::SmallVector<llvm::Metadata*, 4u> >::assign(llvm::SmallVector<llvm::Metadata*, 4u>)
Line
Count
Source
3739
12
  void assign(FieldTy Val) {
3740
12
    Seen = true;
3741
12
    this->Val = std::move(Val);
3742
12
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<long long>::assign(long long)
Line
Count
Source
3739
297
  void assign(FieldTy Val) {
3740
297
    Seen = true;
3741
297
    this->Val = std::move(Val);
3742
297
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::DINode::DIFlags>::assign(llvm::DINode::DIFlags)
Line
Count
Source
3739
3.81k
  void assign(FieldTy Val) {
3740
3.81k
    Seen = true;
3741
3.81k
    this->Val = std::move(Val);
3742
3.81k
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::DIFile::ChecksumKind>::assign(llvm::DIFile::ChecksumKind)
Line
Count
Source
3739
225
  void assign(FieldTy Val) {
3740
225
    Seen = true;
3741
225
    this->Val = std::move(Val);
3742
225
  }
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::DISubprogram::DISPFlags>::assign(llvm::DISubprogram::DISPFlags)
Line
Count
Source
3739
395
  void assign(FieldTy Val) {
3740
395
    Seen = true;
3741
395
    this->Val = std::move(Val);
3742
395
  }
3743
3744
  explicit MDFieldImpl(FieldTy Default)
3745
360k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<unsigned long long>::MDFieldImpl(unsigned long long)
Line
Count
Source
3745
109k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::Metadata*>::MDFieldImpl(llvm::Metadata*)
Line
Count
Source
3745
114k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<bool>::MDFieldImpl(bool)
Line
Count
Source
3745
45.9k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::MDString*>::MDFieldImpl(llvm::MDString*)
Line
Count
Source
3745
52.5k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::SmallVector<llvm::Metadata*, 4u> >::MDFieldImpl(llvm::SmallVector<llvm::Metadata*, 4u>)
Line
Count
Source
3745
39
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<long long>::MDFieldImpl(long long)
Line
Count
Source
3745
16.0k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::DINode::DIFlags>::MDFieldImpl(llvm::DINode::DIFlags)
Line
Count
Source
3745
15.1k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::DIFile::ChecksumKind>::MDFieldImpl(llvm::DIFile::ChecksumKind)
Line
Count
Source
3745
3.10k
      : Val(std::move(Default)), Seen(false) {}
LLParser.cpp:(anonymous namespace)::MDFieldImpl<llvm::DISubprogram::DISPFlags>::MDFieldImpl(llvm::DISubprogram::DISPFlags)
Line
Count
Source
3745
3.72k
      : Val(std::move(Default)), Seen(false) {}
3746
};
3747
3748
/// Structure to represent an optional metadata field that
3749
/// can be of either type (A or B) and encapsulates the
3750
/// MD<typeofA>Field and MD<typeofB>Field structs, so not
3751
/// to reimplement the specifics for representing each Field.
3752
template <class FieldTypeA, class FieldTypeB> struct MDEitherFieldImpl {
3753
  typedef MDEitherFieldImpl<FieldTypeA, FieldTypeB> ImplTy;
3754
  FieldTypeA A;
3755
  FieldTypeB B;
3756
  bool Seen;
3757
3758
  enum {
3759
    IsInvalid = 0,
3760
    IsTypeA = 1,
3761
    IsTypeB = 2
3762
  } WhatIs;
3763
3764
242
  void assign(FieldTypeA A) {
3765
242
    Seen = true;
3766
242
    this->A = std::move(A);
3767
242
    WhatIs = IsTypeA;
3768
242
  }
LLParser.cpp:(anonymous namespace)::MDEitherFieldImpl<(anonymous namespace)::MDSignedField, (anonymous namespace)::MDField>::assign((anonymous namespace)::MDSignedField)
Line
Count
Source
3764
212
  void assign(FieldTypeA A) {
3765
212
    Seen = true;
3766
212
    this->A = std::move(A);
3767
212
    WhatIs = IsTypeA;
3768
212
  }
LLParser.cpp:(anonymous namespace)::MDEitherFieldImpl<(anonymous namespace)::MDSignedField, (anonymous namespace)::MDUnsignedField>::assign((anonymous namespace)::MDSignedField)
Line
Count
Source
3764
30
  void assign(FieldTypeA A) {
3765
30
    Seen = true;
3766
30
    this->A = std::move(A);
3767
30
    WhatIs = IsTypeA;
3768
30
  }
3769
3770
11.8k
  void assign(FieldTypeB B) {
3771
11.8k
    Seen = true;
3772
11.8k
    this->B = std::move(B);
3773
11.8k
    WhatIs = IsTypeB;
3774
11.8k
  }
LLParser.cpp:(anonymous namespace)::MDEitherFieldImpl<(anonymous namespace)::MDSignedField, (anonymous namespace)::MDField>::assign((anonymous namespace)::MDField)
Line
Count
Source
3770
22
  void assign(FieldTypeB B) {
3771
22
    Seen = true;
3772
22
    this->B = std::move(B);
3773
22
    WhatIs = IsTypeB;
3774
22
  }
LLParser.cpp:(anonymous namespace)::MDEitherFieldImpl<(anonymous namespace)::MDSignedField, (anonymous namespace)::MDUnsignedField>::assign((anonymous namespace)::MDUnsignedField)
Line
Count
Source
3770
11.8k
  void assign(FieldTypeB B) {
3771
11.8k
    Seen = true;
3772
11.8k
    this->B = std::move(B);
3773
11.8k
    WhatIs = IsTypeB;
3774
11.8k
  }
3775
3776
  explicit MDEitherFieldImpl(FieldTypeA DefaultA, FieldTypeB DefaultB)
3777
      : A(std::move(DefaultA)), B(std::move(DefaultB)), Seen(false),
3778
12.1k
        WhatIs(IsInvalid) {}
LLParser.cpp:(anonymous namespace)::MDEitherFieldImpl<(anonymous namespace)::MDSignedField, (anonymous namespace)::MDField>::MDEitherFieldImpl((anonymous namespace)::MDSignedField, (anonymous namespace)::MDField)
Line
Count
Source
3778
238
        WhatIs(IsInvalid) {}
LLParser.cpp:(anonymous namespace)::MDEitherFieldImpl<(anonymous namespace)::MDSignedField, (anonymous namespace)::MDUnsignedField>::MDEitherFieldImpl((anonymous namespace)::MDSignedField, (anonymous namespace)::MDUnsignedField)
Line
Count
Source
3778
11.8k
        WhatIs(IsInvalid) {}
3779
};
3780
3781
struct MDUnsignedField : public MDFieldImpl<uint64_t> {
3782
  uint64_t Max;
3783
3784
  MDUnsignedField(uint64_t Default = 0, uint64_t Max = UINT64_MAX)
3785
109k
      : ImplTy(Default), Max(Max) {}
3786
};
3787
3788
struct LineField : public MDUnsignedField {
3789
28.0k
  LineField() : MDUnsignedField(0, UINT32_MAX) {}
3790
};
3791
3792
struct ColumnField : public MDUnsignedField {
3793
11.9k
  ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
3794
};
3795
3796
struct DwarfTagField : public MDUnsignedField {
3797
4.40k
  DwarfTagField() : MDUnsignedField(0, dwarf::DW_TAG_hi_user) {}
3798
  DwarfTagField(dwarf::Tag DefaultTag)
3799
2.00k
      : MDUnsignedField(DefaultTag, dwarf::DW_TAG_hi_user) {}
3800
};
3801
3802
struct DwarfMacinfoTypeField : public MDUnsignedField {
3803
21
  DwarfMacinfoTypeField() : MDUnsignedField(0, dwarf::DW_MACINFO_vendor_ext) {}
3804
  DwarfMacinfoTypeField(dwarf::MacinfoRecordType DefaultType)
3805
27
    : MDUnsignedField(DefaultType, dwarf::DW_MACINFO_vendor_ext) {}
3806
};
3807
3808
struct DwarfAttEncodingField : public MDUnsignedField {
3809
1.94k
  DwarfAttEncodingField() : MDUnsignedField(0, dwarf::DW_ATE_hi_user) {}
3810
};
3811
3812
struct DwarfVirtualityField : public MDUnsignedField {
3813
3.72k
  DwarfVirtualityField() : MDUnsignedField(0, dwarf::DW_VIRTUALITY_max) {}
3814
};
3815
3816
struct DwarfLangField : public MDUnsignedField {
3817
3.71k
  DwarfLangField() : MDUnsignedField(0, dwarf::DW_LANG_hi_user) {}
3818
};
3819
3820
struct DwarfCCField : public MDUnsignedField {
3821
2.44k
  DwarfCCField() : MDUnsignedField(0, dwarf::DW_CC_hi_user) {}
3822
};
3823
3824
struct EmissionKindField : public MDUnsignedField {
3825
2.42k
  EmissionKindField() : MDUnsignedField(0, DICompileUnit::LastEmissionKind) {}
3826
};
3827
3828
struct NameTableKindField : public MDUnsignedField {
3829
  NameTableKindField()
3830
      : MDUnsignedField(
3831
            0, (unsigned)
3832
2.42k
                   DICompileUnit::DebugNameTableKind::LastDebugNameTableKind) {}
3833
};
3834
3835
struct DIFlagField : public MDFieldImpl<DINode::DIFlags> {
3836
15.1k
  DIFlagField() : MDFieldImpl(DINode::FlagZero) {}
3837
};
3838
3839
struct DISPFlagField : public MDFieldImpl<DISubprogram::DISPFlags> {
3840
3.72k
  DISPFlagField() : MDFieldImpl(DISubprogram::SPFlagZero) {}
3841
};
3842
3843
struct MDSignedField : public MDFieldImpl<int64_t> {
3844
  int64_t Min;
3845
  int64_t Max;
3846
3847
  MDSignedField(int64_t Default = 0)
3848
12.1k
      : ImplTy(Default), Min(INT64_MIN), Max(INT64_MAX) {}
3849
  MDSignedField(int64_t Default, int64_t Min, int64_t Max)
3850
3.96k
      : ImplTy(Default), Min(Min), Max(Max) {}
3851
};
3852
3853
struct MDBoolField : public MDFieldImpl<bool> {
3854
45.9k
  MDBoolField(bool Default = false) : ImplTy(Default) {}
3855
};
3856
3857
struct MDField : public MDFieldImpl<Metadata *> {
3858
  bool AllowNull;
3859
3860
114k
  MDField(bool AllowNull = true) : ImplTy(nullptr), AllowNull(AllowNull) {}
3861
};
3862
3863
struct MDConstant : public MDFieldImpl<ConstantAsMetadata *> {
3864
0
  MDConstant() : ImplTy(nullptr) {}
3865
};
3866
3867
struct MDStringField : public MDFieldImpl<MDString *> {
3868
  bool AllowEmpty;
3869
  MDStringField(bool AllowEmpty = true)
3870
52.5k
      : ImplTy(nullptr), AllowEmpty(AllowEmpty) {}
3871
};
3872
3873
struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> {
3874
39
  MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {}
3875
};
3876
3877
struct ChecksumKindField : public MDFieldImpl<DIFile::ChecksumKind> {
3878
3.10k
  ChecksumKindField(DIFile::ChecksumKind CSKind) : ImplTy(CSKind) {}
3879
};
3880
3881
struct MDSignedOrMDField : MDEitherFieldImpl<MDSignedField, MDField> {
3882
  MDSignedOrMDField(int64_t Default = 0, bool AllowNull = true)
3883
0
      : ImplTy(MDSignedField(Default), MDField(AllowNull)) {}
3884
3885
  MDSignedOrMDField(int64_t Default, int64_t Min, int64_t Max,
3886
                    bool AllowNull = true)
3887
238
      : ImplTy(MDSignedField(Default, Min, Max), MDField(AllowNull)) {}
3888
3889
232
  bool isMDSignedField() const { return WhatIs == IsTypeA; }
3890
22
  bool isMDField() const { return WhatIs == IsTypeB; }
3891
210
  int64_t getMDSignedValue() const {
3892
210
    assert(isMDSignedField() && "Wrong field type");
3893
210
    return A.Val;
3894
210
  }
3895
22
  Metadata *getMDFieldValue() const {
3896
22
    assert(isMDField() && "Wrong field type");
3897
22
    return B.Val;
3898
22
  }
3899
};
3900
3901
struct MDSignedOrUnsignedField
3902
    : MDEitherFieldImpl<MDSignedField, MDUnsignedField> {
3903
11.8k
  MDSignedOrUnsignedField() : ImplTy(MDSignedField(0), MDUnsignedField(0)) {}
3904
3905
11.9k
  bool isMDSignedField() const { return WhatIs == IsTypeA; }
3906
0
  bool isMDUnsignedField() const { return WhatIs == IsTypeB; }
3907
30
  int64_t getMDSignedValue() const {
3908
30
    assert(isMDSignedField() && "Wrong field type");
3909
30
    return A.Val;
3910
30
  }
3911
11.8k
  uint64_t getMDUnsignedValue() const {
3912
11.8k
    assert(isMDUnsignedField() && "Wrong field type");
3913
11.8k
    return B.Val;
3914
11.8k
  }
3915
};
3916
3917
} // end anonymous namespace
3918
3919
namespace llvm {
3920
3921
template <>
3922
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
3923
58.5k
                            MDUnsignedField &Result) {
3924
58.5k
  if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
3925
1
    return TokError("expected unsigned integer");
3926
58.5k
3927
58.5k
  auto &U = Lex.getAPSIntVal();
3928
58.5k
  if (U.ugt(Result.Max))
3929
6
    return TokError("value for '" + Name + "' too large, limit is " +
3930
6
                    Twine(Result.Max));
3931
58.4k
  Result.assign(U.getZExtValue());
3932
58.4k
  assert(Result.Val <= Result.Max && "Expected value in range");
3933
58.4k
  Lex.Lex();
3934
58.4k
  return false;
3935
58.4k
}
3936
3937
template <>
3938
24.3k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, LineField &Result) {
3939
24.3k
  return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3940
24.3k
}
3941
template <>
3942
9.21k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, ColumnField &Result) {
3943
9.21k
  return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3944
9.21k
}
3945
3946
template <>
3947
4.85k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) {
3948
4.85k
  if (Lex.getKind() == lltok::APSInt)
3949
22
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3950
4.83k
3951
4.83k
  if (Lex.getKind() != lltok::DwarfTag)
3952
1
    return TokError("expected DWARF tag");
3953
4.83k
3954
4.83k
  unsigned Tag = dwarf::getTag(Lex.getStrVal());
3955
4.83k
  if (Tag == dwarf::DW_TAG_invalid)
3956
1
    return TokError("invalid DWARF tag" + Twine(" '") + Lex.getStrVal() + "'");
3957
4.82k
  assert(Tag <= Result.Max && "Expected valid DWARF tag");
3958
4.82k
3959
4.82k
  Result.assign(Tag);
3960
4.82k
  Lex.Lex();
3961
4.82k
  return false;
3962
4.82k
}
3963
3964
template <>
3965
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
3966
23
                            DwarfMacinfoTypeField &Result) {
3967
23
  if (Lex.getKind() == lltok::APSInt)
3968
0
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3969
23
3970
23
  if (Lex.getKind() != lltok::DwarfMacinfo)
3971
0
    return TokError("expected DWARF macinfo type");
3972
23
3973
23
  unsigned Macinfo = dwarf::getMacinfo(Lex.getStrVal());
3974
23
  if (Macinfo == dwarf::DW_MACINFO_invalid)
3975
0
    return TokError(
3976
0
        "invalid DWARF macinfo type" + Twine(" '") + Lex.getStrVal() + "'");
3977
23
  assert(Macinfo <= Result.Max && "Expected valid DWARF macinfo type");
3978
23
3979
23
  Result.assign(Macinfo);
3980
23
  Lex.Lex();
3981
23
  return false;
3982
23
}
3983
3984
template <>
3985
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
3986
80
                            DwarfVirtualityField &Result) {
3987
80
  if (Lex.getKind() == lltok::APSInt)
3988
0
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3989
80
3990
80
  if (Lex.getKind() != lltok::DwarfVirtuality)
3991
0
    return TokError("expected DWARF virtuality code");
3992
80
3993
80
  unsigned Virtuality = dwarf::getVirtuality(Lex.getStrVal());
3994
80
  if (Virtuality == dwarf::DW_VIRTUALITY_invalid)
3995
0
    return TokError("invalid DWARF virtuality code" + Twine(" '") +
3996
0
                    Lex.getStrVal() + "'");
3997
80
  assert(Virtuality <= Result.Max && "Expected valid DWARF virtuality code");
3998
80
  Result.assign(Virtuality);
3999
80
  Lex.Lex();
4000
80
  return false;
4001
80
}
4002
4003
template <>
4004
2.46k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfLangField &Result) {
4005
2.46k
  if (Lex.getKind() == lltok::APSInt)
4006
14
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4007
2.44k
4008
2.44k
  if (Lex.getKind() != lltok::DwarfLang)
4009
0
    return TokError("expected DWARF language");
4010
2.44k
4011
2.44k
  unsigned Lang = dwarf::getLanguage(Lex.getStrVal());
4012
2.44k
  if (!Lang)
4013
1
    return TokError("invalid DWARF language" + Twine(" '") + Lex.getStrVal() +
4014
1
                    "'");
4015
2.44k
  assert(Lang <= Result.Max && "Expected valid DWARF language");
4016
2.44k
  Result.assign(Lang);
4017
2.44k
  Lex.Lex();
4018
2.44k
  return false;
4019
2.44k
}
4020
4021
template <>
4022
90
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfCCField &Result) {
4023
90
  if (Lex.getKind() == lltok::APSInt)
4024
0
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4025
90
4026
90
  if (Lex.getKind() != lltok::DwarfCC)
4027
0
    return TokError("expected DWARF calling convention");
4028
90
4029
90
  unsigned CC = dwarf::getCallingConvention(Lex.getStrVal());
4030
90
  if (!CC)
4031
0
    return TokError("invalid DWARF calling convention" + Twine(" '") + Lex.getStrVal() +
4032
0
                    "'");
4033
90
  assert(CC <= Result.Max && "Expected valid DWARF calling convention");
4034
90
  Result.assign(CC);
4035
90
  Lex.Lex();
4036
90
  return false;
4037
90
}
4038
4039
template <>
4040
2.34k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, EmissionKindField &Result) {
4041
2.34k
  if (Lex.getKind() == lltok::APSInt)
4042
60
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4043
2.28k
4044
2.28k
  if (Lex.getKind() != lltok::EmissionKind)
4045
0
    return TokError("expected emission kind");
4046
2.28k
4047
2.28k
  auto Kind = DICompileUnit::getEmissionKind(Lex.getStrVal());
4048
2.28k
  if (!Kind)
4049
0
    return TokError("invalid emission kind" + Twine(" '") + Lex.getStrVal() +
4050
0
                    "'");
4051
2.28k
  assert(*Kind <= Result.Max && "Expected valid emission kind");
4052
2.28k
  Result.assign(*Kind);
4053
2.28k
  Lex.Lex();
4054
2.28k
  return false;
4055
2.28k
}
4056
4057
template <>
4058
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
4059
285
                            NameTableKindField &Result) {
4060
285
  if (Lex.getKind() == lltok::APSInt)
4061
0
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4062
285
4063
285
  if (Lex.getKind() != lltok::NameTableKind)
4064
0
    return TokError("expected nameTable kind");
4065
285
4066
285
  auto Kind = DICompileUnit::getNameTableKind(Lex.getStrVal());
4067
285
  if (!Kind)
4068
0
    return TokError("invalid nameTable kind" + Twine(" '") + Lex.getStrVal() +
4069
0
                    "'");
4070
285
  assert(((unsigned)*Kind) <= Result.Max && "Expected valid nameTable kind");
4071
285
  Result.assign((unsigned)*Kind);
4072
285
  Lex.Lex();
4073
285
  return false;
4074
285
}
4075
4076
template <>
4077
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
4078
1.91k
                            DwarfAttEncodingField &Result) {
4079
1.91k
  if (Lex.getKind() == lltok::APSInt)
4080
3
    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4081
1.91k
4082
1.91k
  if (Lex.getKind() != lltok::DwarfAttEncoding)
4083
0
    return TokError("expected DWARF type attribute encoding");
4084
1.91k
4085
1.91k
  unsigned Encoding = dwarf::getAttributeEncoding(Lex.getStrVal());
4086
1.91k
  if (!Encoding)
4087
0
    return TokError("invalid DWARF type attribute encoding" + Twine(" '") +
4088
0
                    Lex.getStrVal() + "'");
4089
1.91k
  assert(Encoding <= Result.Max && "Expected valid DWARF language");
4090
1.91k
  Result.assign(Encoding);
4091
1.91k
  Lex.Lex();
4092
1.91k
  return false;
4093
1.91k
}
4094
4095
/// DIFlagField
4096
///  ::= uint32
4097
///  ::= DIFlagVector
4098
///  ::= DIFlagVector '|' DIFlagFwdDecl '|' uint32 '|' DIFlagPublic
4099
template <>
4100
3.81k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DIFlagField &Result) {
4101
3.81k
4102
3.81k
  // Parser for a single flag.
4103
4.63k
  auto parseFlag = [&](DINode::DIFlags &Val) {
4104
4.63k
    if (Lex.getKind() == lltok::APSInt && 
!Lex.getAPSIntVal().isSigned()2
) {
4105
2
      uint32_t TempVal = static_cast<uint32_t>(Val);
4106
2
      bool Res = ParseUInt32(TempVal);
4107
2
      Val = static_cast<DINode::DIFlags>(TempVal);
4108
2
      return Res;
4109
2
    }
4110
4.63k
4111
4.63k
    if (Lex.getKind() != lltok::DIFlag)
4112
0
      return TokError("expected debug info flag");
4113
4.63k
4114
4.63k
    Val = DINode::getFlag(Lex.getStrVal());
4115
4.63k
    if (!Val)
4116
0
      return TokError(Twine("invalid debug info flag flag '") +
4117
0
                      Lex.getStrVal() + "'");
4118
4.63k
    Lex.Lex();
4119
4.63k
    return false;
4120
4.63k
  };
4121
3.81k
4122
3.81k
  // Parse the flags and combine them together.
4123
3.81k
  DINode::DIFlags Combined = DINode::FlagZero;
4124
4.63k
  do {
4125
4.63k
    DINode::DIFlags Val;
4126
4.63k
    if (parseFlag(Val))
4127
0
      return true;
4128
4.63k
    Combined |= Val;
4129
4.63k
  } while (EatIfPresent(lltok::bar));
4130
3.81k
4131
3.81k
  Result.assign(Combined);
4132
3.81k
  return false;
4133
3.81k
}
4134
4135
/// DISPFlagField
4136
///  ::= uint32
4137
///  ::= DISPFlagVector
4138
///  ::= DISPFlagVector '|' DISPFlag* '|' uint32
4139
template <>
4140
395
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DISPFlagField &Result) {
4141
395
4142
395
  // Parser for a single flag.
4143
608
  auto parseFlag = [&](DISubprogram::DISPFlags &Val) {
4144
608
    if (Lex.getKind() == lltok::APSInt && 
!Lex.getAPSIntVal().isSigned()62
) {
4145
62
      uint32_t TempVal = static_cast<uint32_t>(Val);
4146
62
      bool Res = ParseUInt32(TempVal);
4147
62
      Val = static_cast<DISubprogram::DISPFlags>(TempVal);
4148
62
      return Res;
4149
62
    }
4150
546
4151
546
    if (Lex.getKind() != lltok::DISPFlag)
4152
0
      return TokError("expected debug info flag");
4153
546
4154
546
    Val = DISubprogram::getFlag(Lex.getStrVal());
4155
546
    if (!Val)
4156
0
      return TokError(Twine("invalid subprogram debug info flag '") +
4157
0
                      Lex.getStrVal() + "'");
4158
546
    Lex.Lex();
4159
546
    return false;
4160
546
  };
4161
395
4162
395
  // Parse the flags and combine them together.
4163
395
  DISubprogram::DISPFlags Combined = DISubprogram::SPFlagZero;
4164
608
  do {
4165
608
    DISubprogram::DISPFlags Val;
4166
608
    if (parseFlag(Val))
4167
0
      return true;
4168
608
    Combined |= Val;
4169
608
  } while (EatIfPresent(lltok::bar));
4170
395
4171
395
  Result.assign(Combined);
4172
395
  return false;
4173
395
}
4174
4175
template <>
4176
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
4177
301
                            MDSignedField &Result) {
4178
301
  if (Lex.getKind() != lltok::APSInt)
4179
0
    return TokError("expected signed integer");
4180
301
4181
301
  auto &S = Lex.getAPSIntVal();
4182
301
  if (S < Result.Min)
4183
2
    return TokError("value for '" + Name + "' too small, limit is " +
4184
2
                    Twine(Result.Min));
4185
299
  if (S > Result.Max)
4186
2
    return TokError("value for '" + Name + "' too large, limit is " +
4187
2
                    Twine(Result.Max));
4188
297
  Result.assign(S.getExtValue());
4189
297
  assert(Result.Val >= Result.Min && "Expected value in range");
4190
297
  assert(Result.Val <= Result.Max && "Expected value in range");
4191
297
  Lex.Lex();
4192
297
  return false;
4193
297
}
4194
4195
template <>
4196
14.2k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDBoolField &Result) {
4197
14.2k
  switch (Lex.getKind()) {
4198
14.2k
  default:
4199
0
    return TokError("expected 'true' or 'false'");
4200
14.2k
  case lltok::kw_true:
4201
6.68k
    Result.assign(true);
4202
6.68k
    break;
4203
14.2k
  case lltok::kw_false:
4204
7.52k
    Result.assign(false);
4205
7.52k
    break;
4206
14.2k
  }
4207
14.2k
  Lex.Lex();
4208
14.2k
  return false;
4209
14.2k
}
4210
4211
template <>
4212
64.2k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) {
4213
64.2k
  if (Lex.getKind() == lltok::kw_null) {
4214
788
    if (!Result.AllowNull)
4215
6
      return TokError("'" + Name + "' cannot be null");
4216
782
    Lex.Lex();
4217
782
    Result.assign(nullptr);
4218
782
    return false;
4219
782
  }
4220
63.4k
4221
63.4k
  Metadata *MD;
4222
63.4k
  if (ParseMetadata(MD, nullptr))
4223
0
    return true;
4224
63.4k
4225
63.4k
  Result.assign(MD);
4226
63.4k
  return false;
4227
63.4k
}
4228
4229
template <>
4230
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
4231
237
                            MDSignedOrMDField &Result) {
4232
237
  // Try to parse a signed int.
4233
237
  if (Lex.getKind() == lltok::APSInt) {
4234
214
    MDSignedField Res = Result.A;
4235
214
    if (!ParseMDField(Loc, Name, Res)) {
4236
212
      Result.assign(Res);
4237
212
      return false;
4238
212
    }
4239
2
    return true;
4240
2
  }
4241
23
4242
23
  // Otherwise, try to parse as an MDField.
4243
23
  MDField Res = Result.B;
4244
23
  if (!ParseMDField(Loc, Name, Res)) {
4245
22
    Result.assign(Res);
4246
22
    return false;
4247
22
  }
4248
1
4249
1
  return true;
4250
1
}
4251
4252
template <>
4253
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
4254
11.8k
                            MDSignedOrUnsignedField &Result) {
4255
11.8k
  if (Lex.getKind() != lltok::APSInt)
4256
0
    return false;
4257
11.8k
4258
11.8k
  if (Lex.getAPSIntVal().isSigned()) {
4259
30
    MDSignedField Res = Result.A;
4260
30
    if (ParseMDField(Loc, Name, Res))
4261
0
      return true;
4262
30
    Result.assign(Res);
4263
30
    return false;
4264
30
  }
4265
11.8k
4266
11.8k
  MDUnsignedField Res = Result.B;
4267
11.8k
  if (ParseMDField(Loc, Name, Res))
4268
0
    return true;
4269
11.8k
  Result.assign(Res);
4270
11.8k
  return false;
4271
11.8k
}
4272
4273
template <>
4274
35.2k
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) {
4275
35.2k
  LocTy ValueLoc = Lex.getLoc();
4276
35.2k
  std::string S;
4277
35.2k
  if (ParseStringConstant(S))
4278
0
    return true;
4279
35.2k
4280
35.2k
  if (!Result.AllowEmpty && 
S.empty()1.23k
)
4281
1
    return Error(ValueLoc, "'" + Name + "' cannot be empty");
4282
35.2k
4283
35.2k
  Result.assign(S.empty() ? 
nullptr419
:
MDString::get(Context, S)34.8k
);
4284
35.2k
  return false;
4285
35.2k
}
4286
4287
template <>
4288
12
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDFieldList &Result) {
4289
12
  SmallVector<Metadata *, 4> MDs;
4290
12
  if (ParseMDNodeVector(MDs))
4291
0
    return true;
4292
12
4293
12
  Result.assign(std::move(MDs));
4294
12
  return false;
4295
12
}
4296
4297
template <>
4298
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
4299
225
                            ChecksumKindField &Result) {
4300
225
  Optional<DIFile::ChecksumKind> CSKind =
4301
225
      DIFile::getChecksumKind(Lex.getStrVal());
4302
225
4303
225
  if (Lex.getKind() != lltok::ChecksumKind || !CSKind)
4304
0
    return TokError(
4305
0
        "invalid checksum kind" + Twine(" '") + Lex.getStrVal() + "'");
4306
225
4307
225
  Result.assign(*CSKind);
4308
225
  Lex.Lex();
4309
225
  return false;
4310
225
}
4311
4312
} // end namespace llvm
4313
4314
template <class ParserTy>
4315
48.0k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
188k
  do {
4317
188k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
188k
4320
188k
    if (parseField())
4321
23
      return true;
4322
188k
  } while (EatIfPresent(lltok::comma));
4323
48.0k
4324
48.0k
  
return false48.0k
;
4325
48.0k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDILocation(llvm::MDNode*&, bool)::$_0>(llvm::LLParser::ParseDILocation(llvm::MDNode*&, bool)::$_0)
Line
Count
Source
4315
10.6k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
29.8k
  do {
4317
29.8k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
29.8k
4320
29.8k
    if (parseField())
4321
5
      return true;
4322
29.8k
  } while (EatIfPresent(lltok::comma));
4323
10.6k
4324
10.6k
  
return false10.6k
;
4325
10.6k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseGenericDINode(llvm::MDNode*&, bool)::$_1>(llvm::LLParser::ParseGenericDINode(llvm::MDNode*&, bool)::$_1)
Line
Count
Source
4315
39
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
63
  do {
4317
63
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
63
4320
63
    if (parseField())
4321
3
      return true;
4322
60
  } while (EatIfPresent(lltok::comma));
4323
39
4324
39
  
return false36
;
4325
39
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDISubrange(llvm::MDNode*&, bool)::$_2>(llvm::LLParser::ParseDISubrange(llvm::MDNode*&, bool)::$_2)
Line
Count
Source
4315
238
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
276
  do {
4317
276
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
276
4320
276
    if (parseField())
4321
5
      return true;
4322
271
  } while (EatIfPresent(lltok::comma));
4323
238
4324
238
  
return false233
;
4325
238
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIEnumerator(llvm::MDNode*&, bool)::$_3>(llvm::LLParser::ParseDIEnumerator(llvm::MDNode*&, bool)::$_3)
Line
Count
Source
4315
11.8k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
23.7k
  do {
4317
23.7k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
23.7k
4320
23.7k
    if (parseField())
4321
0
      return true;
4322
23.7k
  } while (EatIfPresent(lltok::comma));
4323
11.8k
4324
11.8k
  return false;
4325
11.8k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIBasicType(llvm::MDNode*&, bool)::$_4>(llvm::LLParser::ParseDIBasicType(llvm::MDNode*&, bool)::$_4)
Line
Count
Source
4315
1.93k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
7.21k
  do {
4317
7.21k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
7.21k
4320
7.21k
    if (parseField())
4321
0
      return true;
4322
7.21k
  } while (EatIfPresent(lltok::comma));
4323
1.93k
4324
1.93k
  return false;
4325
1.93k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIDerivedType(llvm::MDNode*&, bool)::$_5>(llvm::LLParser::ParseDIDerivedType(llvm::MDNode*&, bool)::$_5)
Line
Count
Source
4315
2.81k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
14.7k
  do {
4317
14.7k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
14.7k
4320
14.7k
    if (parseField())
4321
0
      return true;
4322
14.7k
  } while (EatIfPresent(lltok::comma));
4323
2.81k
4324
2.81k
  return false;
4325
2.81k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDICompositeType(llvm::MDNode*&, bool)::$_6>(llvm::LLParser::ParseDICompositeType(llvm::MDNode*&, bool)::$_6)
Line
Count
Source
4315
1.28k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
8.52k
  do {
4317
8.52k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
8.52k
4320
8.52k
    if (parseField())
4321
0
      return true;
4322
8.52k
  } while (EatIfPresent(lltok::comma));
4323
1.28k
4324
1.28k
  return false;
4325
1.28k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDISubroutineType(llvm::MDNode*&, bool)::$_7>(llvm::LLParser::ParseDISubroutineType(llvm::MDNode*&, bool)::$_7)
Line
Count
Source
4315
2.44k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
2.55k
  do {
4317
2.55k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
2.55k
4320
2.55k
    if (parseField())
4321
0
      return true;
4322
2.55k
  } while (EatIfPresent(lltok::comma));
4323
2.44k
4324
2.44k
  return false;
4325
2.44k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIFile(llvm::MDNode*&, bool)::$_8>(llvm::LLParser::ParseDIFile(llvm::MDNode*&, bool)::$_8)
Line
Count
Source
4315
3.10k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
6.69k
  do {
4317
6.69k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
6.69k
4320
6.69k
    if (parseField())
4321
0
      return true;
4322
6.69k
  } while (EatIfPresent(lltok::comma));
4323
3.10k
4324
3.10k
  return false;
4325
3.10k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDICompileUnit(llvm::MDNode*&, bool)::$_9>(llvm::LLParser::ParseDICompileUnit(llvm::MDNode*&, bool)::$_9)
Line
Count
Source
4315
2.42k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
18.6k
  do {
4317
18.6k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
18.6k
4320
18.6k
    if (parseField())
4321
4
      return true;
4322
18.6k
  } while (EatIfPresent(lltok::comma));
4323
2.42k
4324
2.42k
  
return false2.41k
;
4325
2.42k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDISubprogram(llvm::MDNode*&, bool)::$_10>(llvm::LLParser::ParseDISubprogram(llvm::MDNode*&, bool)::$_10)
Line
Count
Source
4315
3.71k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
41.5k
  do {
4317
41.5k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
41.5k
4320
41.5k
    if (parseField())
4321
0
      return true;
4322
41.5k
  } while (EatIfPresent(lltok::comma));
4323
3.71k
4324
3.71k
  return false;
4325
3.71k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDILexicalBlock(llvm::MDNode*&, bool)::$_11>(llvm::LLParser::ParseDILexicalBlock(llvm::MDNode*&, bool)::$_11)
Line
Count
Source
4315
1.25k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
4.90k
  do {
4317
4.90k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
4.90k
4320
4.90k
    if (parseField())
4321
1
      return true;
4322
4.89k
  } while (EatIfPresent(lltok::comma));
4323
1.25k
4324
1.25k
  
return false1.25k
;
4325
1.25k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDILexicalBlockFile(llvm::MDNode*&, bool)::$_12>(llvm::LLParser::ParseDILexicalBlockFile(llvm::MDNode*&, bool)::$_12)
Line
Count
Source
4315
245
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
722
  do {
4317
722
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
722
4320
722
    if (parseField())
4321
1
      return true;
4322
721
  } while (EatIfPresent(lltok::comma));
4323
245
4324
245
  
return false244
;
4325
245
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDICommonBlock(llvm::MDNode*&, bool)::$_13>(llvm::LLParser::ParseDICommonBlock(llvm::MDNode*&, bool)::$_13)
Line
Count
Source
4315
3
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
15
  do {
4317
15
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
15
4320
15
    if (parseField())
4321
0
      return true;
4322
15
  } while (EatIfPresent(lltok::comma));
4323
3
4324
3
  return false;
4325
3
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDINamespace(llvm::MDNode*&, bool)::$_14>(llvm::LLParser::ParseDINamespace(llvm::MDNode*&, bool)::$_14)
Line
Count
Source
4315
114
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
216
  do {
4317
216
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
216
4320
216
    if (parseField())
4321
0
      return true;
4322
216
  } while (EatIfPresent(lltok::comma));
4323
114
4324
114
  return false;
4325
114
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIMacro(llvm::MDNode*&, bool)::$_15>(llvm::LLParser::ParseDIMacro(llvm::MDNode*&, bool)::$_15)
Line
Count
Source
4315
21
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
77
  do {
4317
77
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
77
4320
77
    if (parseField())
4321
0
      return true;
4322
77
  } while (EatIfPresent(lltok::comma));
4323
21
4324
21
  return false;
4325
21
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIMacroFile(llvm::MDNode*&, bool)::$_16>(llvm::LLParser::ParseDIMacroFile(llvm::MDNode*&, bool)::$_16)
Line
Count
Source
4315
27
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
70
  do {
4317
70
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
70
4320
70
    if (parseField())
4321
0
      return true;
4322
70
  } while (EatIfPresent(lltok::comma));
4323
27
4324
27
  return false;
4325
27
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIModule(llvm::MDNode*&, bool)::$_17>(llvm::LLParser::ParseDIModule(llvm::MDNode*&, bool)::$_17)
Line
Count
Source
4315
23
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
81
  do {
4317
81
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
81
4320
81
    if (parseField())
4321
0
      return true;
4322
81
  } while (EatIfPresent(lltok::comma));
4323
23
4324
23
  return false;
4325
23
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDITemplateTypeParameter(llvm::MDNode*&, bool)::$_18>(llvm::LLParser::ParseDITemplateTypeParameter(llvm::MDNode*&, bool)::$_18)
Line
Count
Source
4315
72
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
119
  do {
4317
119
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
119
4320
119
    if (parseField())
4321
0
      return true;
4322
119
  } while (EatIfPresent(lltok::comma));
4323
72
4324
72
  return false;
4325
72
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDITemplateValueParameter(llvm::MDNode*&, bool)::$_19>(llvm::LLParser::ParseDITemplateValueParameter(llvm::MDNode*&, bool)::$_19)
Line
Count
Source
4315
57
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
164
  do {
4317
164
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
164
4320
164
    if (parseField())
4321
0
      return true;
4322
164
  } while (EatIfPresent(lltok::comma));
4323
57
4324
57
  return false;
4325
57
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIGlobalVariable(llvm::MDNode*&, bool)::$_20>(llvm::LLParser::ParseDIGlobalVariable(llvm::MDNode*&, bool)::$_20)
Line
Count
Source
4315
1.23k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
8.81k
  do {
4317
8.81k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
8.81k
4320
8.81k
    if (parseField())
4321
1
      return true;
4322
8.81k
  } while (EatIfPresent(lltok::comma));
4323
1.23k
4324
1.23k
  
return false1.23k
;
4325
1.23k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDILocalVariable(llvm::MDNode*&, bool)::$_21>(llvm::LLParser::ParseDILocalVariable(llvm::MDNode*&, bool)::$_21)
Line
Count
Source
4315
2.96k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
15.8k
  do {
4317
15.8k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
15.8k
4320
15.8k
    if (parseField())
4321
3
      return true;
4322
15.8k
  } while (EatIfPresent(lltok::comma));
4323
2.96k
4324
2.96k
  
return false2.96k
;
4325
2.96k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDILabel(llvm::MDNode*&, bool)::$_22>(llvm::LLParser::ParseDILabel(llvm::MDNode*&, bool)::$_22)
Line
Count
Source
4315
26
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
104
  do {
4317
104
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
104
4320
104
    if (parseField())
4321
0
      return true;
4322
104
  } while (EatIfPresent(lltok::comma));
4323
26
4324
26
  return false;
4325
26
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIGlobalVariableExpression(llvm::MDNode*&, bool)::$_23>(llvm::LLParser::ParseDIGlobalVariableExpression(llvm::MDNode*&, bool)::$_23)
Line
Count
Source
4315
1.21k
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
2.42k
  do {
4317
2.42k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
2.42k
4320
2.42k
    if (parseField())
4321
0
      return true;
4322
2.42k
  } while (EatIfPresent(lltok::comma));
4323
1.21k
4324
1.21k
  return false;
4325
1.21k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIObjCProperty(llvm::MDNode*&, bool)::$_24>(llvm::LLParser::ParseDIObjCProperty(llvm::MDNode*&, bool)::$_24)
Line
Count
Source
4315
14
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
75
  do {
4317
75
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
75
4320
75
    if (parseField())
4321
0
      return true;
4322
75
  } while (EatIfPresent(lltok::comma));
4323
14
4324
14
  return false;
4325
14
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImplBody<llvm::LLParser::ParseDIImportedEntity(llvm::MDNode*&, bool)::$_25>(llvm::LLParser::ParseDIImportedEntity(llvm::MDNode*&, bool)::$_25)
Line
Count
Source
4315
264
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
4316
1.28k
  do {
4317
1.28k
    if (Lex.getKind() != lltok::LabelStr)
4318
0
      return TokError("expected field label here");
4319
1.28k
4320
1.28k
    if (parseField())
4321
0
      return true;
4322
1.28k
  } while (EatIfPresent(lltok::comma));
4323
264
4324
264
  return false;
4325
264
}
4326
4327
template <class ParserTy>
4328
48.1k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
48.1k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
48.1k
  Lex.Lex();
4331
48.1k
4332
48.1k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
48.1k
  if (Lex.getKind() != lltok::rparen)
4335
48.0k
    if (ParseMDFieldsImplBody(parseField))
4336
23
      return true;
4337
48.0k
4338
48.0k
  ClosingLoc = Lex.getLoc();
4339
48.0k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
48.0k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDILocation(llvm::MDNode*&, bool)::$_0>(llvm::LLParser::ParseDILocation(llvm::MDNode*&, bool)::$_0, llvm::SMLoc&)
Line
Count
Source
4328
10.6k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
10.6k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
10.6k
  Lex.Lex();
4331
10.6k
4332
10.6k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
10.6k
  if (Lex.getKind() != lltok::rparen)
4335
10.6k
    if (ParseMDFieldsImplBody(parseField))
4336
5
      return true;
4337
10.6k
4338
10.6k
  ClosingLoc = Lex.getLoc();
4339
10.6k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
10.6k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseGenericDINode(llvm::MDNode*&, bool)::$_1>(llvm::LLParser::ParseGenericDINode(llvm::MDNode*&, bool)::$_1, llvm::SMLoc&)
Line
Count
Source
4328
39
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
39
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
39
  Lex.Lex();
4331
39
4332
39
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
39
  if (Lex.getKind() != lltok::rparen)
4335
39
    if (ParseMDFieldsImplBody(parseField))
4336
3
      return true;
4337
36
4338
36
  ClosingLoc = Lex.getLoc();
4339
36
  return ParseToken(lltok::rparen, "expected ')' here");
4340
36
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDISubrange(llvm::MDNode*&, bool)::$_2>(llvm::LLParser::ParseDISubrange(llvm::MDNode*&, bool)::$_2, llvm::SMLoc&)
Line
Count
Source
4328
238
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
238
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
238
  Lex.Lex();
4331
238
4332
238
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
238
  if (Lex.getKind() != lltok::rparen)
4335
238
    if (ParseMDFieldsImplBody(parseField))
4336
5
      return true;
4337
233
4338
233
  ClosingLoc = Lex.getLoc();
4339
233
  return ParseToken(lltok::rparen, "expected ')' here");
4340
233
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIEnumerator(llvm::MDNode*&, bool)::$_3>(llvm::LLParser::ParseDIEnumerator(llvm::MDNode*&, bool)::$_3, llvm::SMLoc&)
Line
Count
Source
4328
11.8k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
11.8k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
11.8k
  Lex.Lex();
4331
11.8k
4332
11.8k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
11.8k
  if (Lex.getKind() != lltok::rparen)
4335
11.8k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
11.8k
4338
11.8k
  ClosingLoc = Lex.getLoc();
4339
11.8k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
11.8k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIBasicType(llvm::MDNode*&, bool)::$_4>(llvm::LLParser::ParseDIBasicType(llvm::MDNode*&, bool)::$_4, llvm::SMLoc&)
Line
Count
Source
4328
1.94k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
1.94k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
1.94k
  Lex.Lex();
4331
1.94k
4332
1.94k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
1.94k
  if (Lex.getKind() != lltok::rparen)
4335
1.93k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
1.94k
4338
1.94k
  ClosingLoc = Lex.getLoc();
4339
1.94k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
1.94k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIDerivedType(llvm::MDNode*&, bool)::$_5>(llvm::LLParser::ParseDIDerivedType(llvm::MDNode*&, bool)::$_5, llvm::SMLoc&)
Line
Count
Source
4328
2.81k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
2.81k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
2.81k
  Lex.Lex();
4331
2.81k
4332
2.81k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
2.81k
  if (Lex.getKind() != lltok::rparen)
4335
2.81k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
2.81k
4338
2.81k
  ClosingLoc = Lex.getLoc();
4339
2.81k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
2.81k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDICompositeType(llvm::MDNode*&, bool)::$_6>(llvm::LLParser::ParseDICompositeType(llvm::MDNode*&, bool)::$_6, llvm::SMLoc&)
Line
Count
Source
4328
1.28k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
1.28k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
1.28k
  Lex.Lex();
4331
1.28k
4332
1.28k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
1.28k
  if (Lex.getKind() != lltok::rparen)
4335
1.28k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
1.28k
4338
1.28k
  ClosingLoc = Lex.getLoc();
4339
1.28k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
1.28k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDISubroutineType(llvm::MDNode*&, bool)::$_7>(llvm::LLParser::ParseDISubroutineType(llvm::MDNode*&, bool)::$_7, llvm::SMLoc&)
Line
Count
Source
4328
2.44k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
2.44k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
2.44k
  Lex.Lex();
4331
2.44k
4332
2.44k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
2.44k
  if (Lex.getKind() != lltok::rparen)
4335
2.44k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
2.44k
4338
2.44k
  ClosingLoc = Lex.getLoc();
4339
2.44k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
2.44k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIFile(llvm::MDNode*&, bool)::$_8>(llvm::LLParser::ParseDIFile(llvm::MDNode*&, bool)::$_8, llvm::SMLoc&)
Line
Count
Source
4328
3.10k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
3.10k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
3.10k
  Lex.Lex();
4331
3.10k
4332
3.10k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
3.10k
  if (Lex.getKind() != lltok::rparen)
4335
3.10k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
3.10k
4338
3.10k
  ClosingLoc = Lex.getLoc();
4339
3.10k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
3.10k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDICompileUnit(llvm::MDNode*&, bool)::$_9>(llvm::LLParser::ParseDICompileUnit(llvm::MDNode*&, bool)::$_9, llvm::SMLoc&)
Line
Count
Source
4328
2.42k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
2.42k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
2.42k
  Lex.Lex();
4331
2.42k
4332
2.42k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
2.42k
  if (Lex.getKind() != lltok::rparen)
4335
2.42k
    if (ParseMDFieldsImplBody(parseField))
4336
4
      return true;
4337
2.41k
4338
2.41k
  ClosingLoc = Lex.getLoc();
4339
2.41k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
2.41k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDISubprogram(llvm::MDNode*&, bool)::$_10>(llvm::LLParser::ParseDISubprogram(llvm::MDNode*&, bool)::$_10, llvm::SMLoc&)
Line
Count
Source
4328
3.72k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
3.72k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
3.72k
  Lex.Lex();
4331
3.72k
4332
3.72k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
3.72k
  if (Lex.getKind() != lltok::rparen)
4335
3.71k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
3.72k
4338
3.72k
  ClosingLoc = Lex.getLoc();
4339
3.72k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
3.72k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDILexicalBlock(llvm::MDNode*&, bool)::$_11>(llvm::LLParser::ParseDILexicalBlock(llvm::MDNode*&, bool)::$_11, llvm::SMLoc&)
Line
Count
Source
4328
1.25k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
1.25k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
1.25k
  Lex.Lex();
4331
1.25k
4332
1.25k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
1.25k
  if (Lex.getKind() != lltok::rparen)
4335
1.25k
    if (ParseMDFieldsImplBody(parseField))
4336
1
      return true;
4337
1.25k
4338
1.25k
  ClosingLoc = Lex.getLoc();
4339
1.25k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
1.25k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDILexicalBlockFile(llvm::MDNode*&, bool)::$_12>(llvm::LLParser::ParseDILexicalBlockFile(llvm::MDNode*&, bool)::$_12, llvm::SMLoc&)
Line
Count
Source
4328
245
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
245
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
245
  Lex.Lex();
4331
245
4332
245
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
245
  if (Lex.getKind() != lltok::rparen)
4335
245
    if (ParseMDFieldsImplBody(parseField))
4336
1
      return true;
4337
244
4338
244
  ClosingLoc = Lex.getLoc();
4339
244
  return ParseToken(lltok::rparen, "expected ')' here");
4340
244
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDICommonBlock(llvm::MDNode*&, bool)::$_13>(llvm::LLParser::ParseDICommonBlock(llvm::MDNode*&, bool)::$_13, llvm::SMLoc&)
Line
Count
Source
4328
3
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
3
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
3
  Lex.Lex();
4331
3
4332
3
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
3
  if (Lex.getKind() != lltok::rparen)
4335
3
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
3
4338
3
  ClosingLoc = Lex.getLoc();
4339
3
  return ParseToken(lltok::rparen, "expected ')' here");
4340
3
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDINamespace(llvm::MDNode*&, bool)::$_14>(llvm::LLParser::ParseDINamespace(llvm::MDNode*&, bool)::$_14, llvm::SMLoc&)
Line
Count
Source
4328
114
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
114
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
114
  Lex.Lex();
4331
114
4332
114
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
114
  if (Lex.getKind() != lltok::rparen)
4335
114
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
114
4338
114
  ClosingLoc = Lex.getLoc();
4339
114
  return ParseToken(lltok::rparen, "expected ')' here");
4340
114
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIMacro(llvm::MDNode*&, bool)::$_15>(llvm::LLParser::ParseDIMacro(llvm::MDNode*&, bool)::$_15, llvm::SMLoc&)
Line
Count
Source
4328
21
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
21
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
21
  Lex.Lex();
4331
21
4332
21
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
21
  if (Lex.getKind() != lltok::rparen)
4335
21
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
21
4338
21
  ClosingLoc = Lex.getLoc();
4339
21
  return ParseToken(lltok::rparen, "expected ')' here");
4340
21
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIMacroFile(llvm::MDNode*&, bool)::$_16>(llvm::LLParser::ParseDIMacroFile(llvm::MDNode*&, bool)::$_16, llvm::SMLoc&)
Line
Count
Source
4328
27
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
27
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
27
  Lex.Lex();
4331
27
4332
27
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
27
  if (Lex.getKind() != lltok::rparen)
4335
27
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
27
4338
27
  ClosingLoc = Lex.getLoc();
4339
27
  return ParseToken(lltok::rparen, "expected ')' here");
4340
27
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIModule(llvm::MDNode*&, bool)::$_17>(llvm::LLParser::ParseDIModule(llvm::MDNode*&, bool)::$_17, llvm::SMLoc&)
Line
Count
Source
4328
23
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
23
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
23
  Lex.Lex();
4331
23
4332
23
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
23
  if (Lex.getKind() != lltok::rparen)
4335
23
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
23
4338
23
  ClosingLoc = Lex.getLoc();
4339
23
  return ParseToken(lltok::rparen, "expected ')' here");
4340
23
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDITemplateTypeParameter(llvm::MDNode*&, bool)::$_18>(llvm::LLParser::ParseDITemplateTypeParameter(llvm::MDNode*&, bool)::$_18, llvm::SMLoc&)
Line
Count
Source
4328
72
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
72
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
72
  Lex.Lex();
4331
72
4332
72
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
72
  if (Lex.getKind() != lltok::rparen)
4335
72
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
72
4338
72
  ClosingLoc = Lex.getLoc();
4339
72
  return ParseToken(lltok::rparen, "expected ')' here");
4340
72
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDITemplateValueParameter(llvm::MDNode*&, bool)::$_19>(llvm::LLParser::ParseDITemplateValueParameter(llvm::MDNode*&, bool)::$_19, llvm::SMLoc&)
Line
Count
Source
4328
57
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
57
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
57
  Lex.Lex();
4331
57
4332
57
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
57
  if (Lex.getKind() != lltok::rparen)
4335
57
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
57
4338
57
  ClosingLoc = Lex.getLoc();
4339
57
  return ParseToken(lltok::rparen, "expected ')' here");
4340
57
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIGlobalVariable(llvm::MDNode*&, bool)::$_20>(llvm::LLParser::ParseDIGlobalVariable(llvm::MDNode*&, bool)::$_20, llvm::SMLoc&)
Line
Count
Source
4328
1.23k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
1.23k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
1.23k
  Lex.Lex();
4331
1.23k
4332
1.23k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
1.23k
  if (Lex.getKind() != lltok::rparen)
4335
1.23k
    if (ParseMDFieldsImplBody(parseField))
4336
1
      return true;
4337
1.23k
4338
1.23k
  ClosingLoc = Lex.getLoc();
4339
1.23k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
1.23k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDILocalVariable(llvm::MDNode*&, bool)::$_21>(llvm::LLParser::ParseDILocalVariable(llvm::MDNode*&, bool)::$_21, llvm::SMLoc&)
Line
Count
Source
4328
2.96k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
2.96k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
2.96k
  Lex.Lex();
4331
2.96k
4332
2.96k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
2.96k
  if (Lex.getKind() != lltok::rparen)
4335
2.96k
    if (ParseMDFieldsImplBody(parseField))
4336
3
      return true;
4337
2.96k
4338
2.96k
  ClosingLoc = Lex.getLoc();
4339
2.96k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
2.96k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDILabel(llvm::MDNode*&, bool)::$_22>(llvm::LLParser::ParseDILabel(llvm::MDNode*&, bool)::$_22, llvm::SMLoc&)
Line
Count
Source
4328
26
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
26
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
26
  Lex.Lex();
4331
26
4332
26
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
26
  if (Lex.getKind() != lltok::rparen)
4335
26
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
26
4338
26
  ClosingLoc = Lex.getLoc();
4339
26
  return ParseToken(lltok::rparen, "expected ')' here");
4340
26
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIGlobalVariableExpression(llvm::MDNode*&, bool)::$_23>(llvm::LLParser::ParseDIGlobalVariableExpression(llvm::MDNode*&, bool)::$_23, llvm::SMLoc&)
Line
Count
Source
4328
1.21k
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
1.21k
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
1.21k
  Lex.Lex();
4331
1.21k
4332
1.21k
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
1.21k
  if (Lex.getKind() != lltok::rparen)
4335
1.21k
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
1.21k
4338
1.21k
  ClosingLoc = Lex.getLoc();
4339
1.21k
  return ParseToken(lltok::rparen, "expected ')' here");
4340
1.21k
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIObjCProperty(llvm::MDNode*&, bool)::$_24>(llvm::LLParser::ParseDIObjCProperty(llvm::MDNode*&, bool)::$_24, llvm::SMLoc&)
Line
Count
Source
4328
21
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
21
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
21
  Lex.Lex();
4331
21
4332
21
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
21
  if (Lex.getKind() != lltok::rparen)
4335
14
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
21
4338
21
  ClosingLoc = Lex.getLoc();
4339
21
  return ParseToken(lltok::rparen, "expected ')' here");
4340
21
}
LLParser.cpp:bool llvm::LLParser::ParseMDFieldsImpl<llvm::LLParser::ParseDIImportedEntity(llvm::MDNode*&, bool)::$_25>(llvm::LLParser::ParseDIImportedEntity(llvm::MDNode*&, bool)::$_25, llvm::SMLoc&)
Line
Count
Source
4328
264
bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
4329
264
  assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
4330
264
  Lex.Lex();
4331
264
4332
264
  if (ParseToken(lltok::lparen, "expected '(' here"))
4333
0
    return true;
4334
264
  if (Lex.getKind() != lltok::rparen)
4335
264
    if (ParseMDFieldsImplBody(parseField))
4336
0
      return true;
4337
264
4338
264
  ClosingLoc = Lex.getLoc();
4339
264
  return ParseToken(lltok::rparen, "expected ')' here");
4340
264
}
4341
4342
template <class FieldTy>
4343
188k
bool LLParser::ParseMDField(StringRef Name, FieldTy &Result) {
4344
188k
  if (Result.Seen)
4345
1
    return TokError("field '" + Name + "' cannot be specified more than once");
4346
188k
4347
188k
  LocTy Loc = Lex.getLoc();
4348
188k
  Lex.Lex();
4349
188k
  return ParseMDField(Loc, Name, Result);
4350
188k
}