Skip to content

TableGen compiler points to non-existent line when source is just a single #ifdef (and crashes on one platform) #151476

@DavidSpickett

Description

@DavidSpickett
#ifdef FOO
$ ./bin/llvm-tblgen /tmp/test.td
/tmp/test.td:2:1: error: reached EOF without matching #endif

^
/tmp/test.td:1:8: error: the latest preprocessor control is here
#ifdef FOO
       ^
/tmp/test.td:2:1: error: Unexpected token at top level

^

Clearly test.td:2:1 does not exist, or is the actual EOF character. It should not be complaining about that as well as the lack of #endif.

Also, this currently crashes on Compiler Explorer https://godbolt.org/z/KvETG5Yah:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/llvm-tblgen -o /app/output.s -I/opt/compiler-explorer/clang-trunk/include/ <source>
 #0 0x0000000000729758 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x729758)
 #1 0x0000000000726bd4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007947c3042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000000764cd0 llvm::TGLexer::prepSkipRegion(bool) (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x764cd0)
 #4 0x0000000000763c29 llvm::TGLexer::lexPreprocessor(llvm::tgtok::TokKind, bool) (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x763c29)
 #5 0x000000000076409d llvm::TGLexer::LexToken(bool) (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x76409d)
 #6 0x000000000077d794 llvm::TGParser::ParseFile() (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x77d794)
 #7 0x0000000000735cfc llvm::TableGenMain(char const*, std::function<bool (llvm::raw_ostream&, llvm::RecordKeeper const&)>) (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x735cfc)
 #8 0x000000000044e5af tblgen_main(int, char**) (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x44e5af)
 #9 0x00007947c3029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#10 0x00007947c3029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#11 0x000000000040b2b5 _start (/opt/compiler-explorer/clang-trunk/bin/llvm-tblgen+0x40b2b5)
Program terminated with signal: SIGSEGV
Compiler returned: 139

I could not get it to crash on x86 or AArch64 with asserts on or off or with ubsan or asan. Looking at prepSkipRegion, I suspect that the pointer to the current character is incremented multiple times during a loop body, but the curPtr != end of text is only being checked at the end or start.

Perhaps memory allocation on various systems hides this problem. Compiler Explorer's copy is running on x86 Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions