[TableGen] Fix incorrect handling of nested #ifndef directives
TableGen's lexer was unable to handle nested #ifndef when the outer `#ifdef` / `#ifndef` scope is subject to skip. This was caused by returning the canonicalized token when it should have returned the original one. Fix #65100. Differential Revision: https://reviews.llvm.org/D159236
This commit is contained in:
parent
f9fe6032cd
commit
a09f09c618
@ -723,16 +723,15 @@ tgtok::TokKind TGLexer::lexPreprocessor(
|
||||
|
||||
bool MacroIsDefined = DefinedMacros.count(MacroName) != 0;
|
||||
|
||||
// Canonicalize ifndef to ifdef equivalent
|
||||
if (Kind == tgtok::Ifndef) {
|
||||
// Canonicalize ifndef's MacroIsDefined to its ifdef equivalent.
|
||||
if (Kind == tgtok::Ifndef)
|
||||
MacroIsDefined = !MacroIsDefined;
|
||||
Kind = tgtok::Ifdef;
|
||||
}
|
||||
|
||||
// Regardless of whether we are processing tokens or not,
|
||||
// we put the #ifdef control on stack.
|
||||
// Note that MacroIsDefined has been canonicalized against ifdef.
|
||||
PrepIncludeStack.back()->push_back(
|
||||
{Kind, MacroIsDefined, SMLoc::getFromPointer(TokStart)});
|
||||
{tgtok::Ifdef, MacroIsDefined, SMLoc::getFromPointer(TokStart)});
|
||||
|
||||
if (!prepSkipDirectiveEnd())
|
||||
return ReturnError(CurPtr, "Only comments are supported after " +
|
||||
|
||||
10
llvm/test/TableGen/nested_ifdef.inc
Normal file
10
llvm/test/TableGen/nested_ifdef.inc
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef NESTED_IFDEF
|
||||
#define NESTED_IFDEF
|
||||
|
||||
def foo;
|
||||
|
||||
#ifndef HAHA
|
||||
def haha;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
8
llvm/test/TableGen/nested_ifdef2.inc
Normal file
8
llvm/test/TableGen/nested_ifdef2.inc
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef NESTED_IFDEF2
|
||||
#define NESTED_IFDEF2
|
||||
|
||||
include "nested_ifdef.inc"
|
||||
|
||||
def bar;
|
||||
|
||||
#endif
|
||||
11
llvm/test/TableGen/nested_ifdef_main.td
Normal file
11
llvm/test/TableGen/nested_ifdef_main.td
Normal file
@ -0,0 +1,11 @@
|
||||
// RUN: llvm-tblgen -I %p %s | FileCheck %s
|
||||
|
||||
include "nested_ifdef.inc"
|
||||
include "nested_ifdef2.inc"
|
||||
|
||||
// CHECK: def bar
|
||||
// CHECK: def foo
|
||||
// CHECK: def haha
|
||||
// CHECK: def zoo
|
||||
|
||||
def zoo;
|
||||
Loading…
x
Reference in New Issue
Block a user