diff options
-rw-r--r-- | llvm/lib/TableGen/TGParser.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGParser.h | 8 | ||||
-rw-r--r-- | llvm/test/TableGen/ValidIdentifiers.td | 13 |
3 files changed, 24 insertions, 9 deletions
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index daac5747d3e..38ab71184aa 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -380,10 +380,11 @@ static bool isObjectStart(tgtok::TokKind K) { K == tgtok::MultiClass || K == tgtok::Foreach; } -static std::string GetNewAnonymousName() { - static unsigned AnonCounter = 0; +/// GetNewAnonymousName - Generate a unique anonymous name that can be used as +/// an identifier. +std::string TGParser::GetNewAnonymousName() { unsigned Tmp = AnonCounter++; // MSVC2012 ICEs without this. - return "anonymous." + utostr(Tmp); + return "anonymous_" + utostr(Tmp); } /// ParseObjectName - If an object name is specified, return it. Otherwise, @@ -1215,10 +1216,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, SMLoc EndLoc = Lex.getLoc(); // Create the new record, set it as CurRec temporarily. - static unsigned AnonCounter = 0; - Record *NewRec = new Record("anonymous.val."+utostr(AnonCounter++), - NameLoc, - Records, + Record *NewRec = new Record(GetNewAnonymousName(), NameLoc, Records, /*IsAnonymous=*/true); SubClassReference SCRef; SCRef.RefRange = SMRange(NameLoc, EndLoc); diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h index 044e3a02ba4..a5753458108 100644 --- a/llvm/lib/TableGen/TGParser.h +++ b/llvm/lib/TableGen/TGParser.h @@ -69,6 +69,8 @@ class TGParser { // Record tracker RecordKeeper &Records; + unsigned AnonCounter; + // A "named boolean" indicating how to parse identifiers. Usually // identifiers map to some existing object but in special cases // (e.g. parsing def names) no such object exists yet because we are @@ -82,8 +84,8 @@ class TGParser { }; public: - TGParser(SourceMgr &SrcMgr, RecordKeeper &records) : - Lex(SrcMgr), CurMultiClass(0), Records(records) {} + TGParser(SourceMgr &SrcMgr, RecordKeeper &records) + : Lex(SrcMgr), CurMultiClass(0), Records(records), AnonCounter(0) {} /// ParseFile - Main entrypoint for parsing a tblgen file. These parser /// routines return true on error, or false on success. @@ -112,6 +114,8 @@ private: // Semantic analysis methods. bool AddSubMultiClass(MultiClass *CurMC, SubMultiClassReference &SubMultiClass); + std::string GetNewAnonymousName(); + // IterRecord: Map an iterator name to a value. struct IterRecord { VarInit *IterVar; diff --git a/llvm/test/TableGen/ValidIdentifiers.td b/llvm/test/TableGen/ValidIdentifiers.td new file mode 100644 index 00000000000..899ae0e3868 --- /dev/null +++ b/llvm/test/TableGen/ValidIdentifiers.td @@ -0,0 +1,13 @@ +// Ensure that anonymous names are valid identifiers via the ctags index +// RUN: llvm-tblgen -gen-ctags %s | grep -v '^!' | not grep -viE '^[a-z_][a-z0-9_]*\t' +// Test validation +// RUN: llvm-tblgen -gen-ctags %s | grep '^anonymous' > /dev/null +// XFAIL: vg_leak + +class foo<int X> { int THEVAL = X; } + +def : foo<2>; + +def X { + foo Y = foo<1>; +} |