uw-pluverse / perses

language-agnostic program reducer.
GNU General Public License v3.0
171 stars 24 forks source link

Perses 1.6 crashes on token paste operator in C programs #25

Closed rkchang closed 11 months ago

rkchang commented 11 months ago

When Perses encounters a token paste operator in a C program it throws an exception and then hangs. Probably the same issue as #23

❯ java -jar perses_deploy.jar --version
perses version 1.6
Git Version: 782478b56624fa61a87f4f4fab044604ff986803
Git Branch: master
Git Status: Modified
Built on 2023-04-10T01:18:27.404399-04:00[America/Toronto]

perses_test.c:

#define TEST(x) x##1

int main(void) {
    return TEST(0);
}

perses_test.sh

#!/bin/bash

gcc perses_test.c -o perses_test

Error:

❯ java -jar perses_deploy.jar --test-script perses_test.sh --input-file perses_test.c
[18:53:56] [INFO   ] Tree Building: Start building spar-tree from input file SourceFile{file=FileWithContent{file=/home/rkchang/dev/omp/perses_test.c}, lang=LanguageC{name=c, extensions=[c], defaultCodeFormatControl=SINGLE_TOKEN_PER_LINE}}
[18:53:56] [INFO   ] Tree Building: Step 1: Antlr parsing.
Exception in thread "main" org.perses.grammar.AntlrFailureException: Error in parsing file: <in memory>
Details: recognizer: org.perses.grammar.c.PnfCLexer@5bd1ceca
offendingSymbol: null
line: 1
column: 17
msg: token recognition error at: '##'

Caused by: LexerNoViableAltException('#')
    at org.antlr.v4.runtime.atn.LexerATNSimulator.failOrAccept(LexerATNSimulator.java:309)
    at org.antlr.v4.runtime.atn.LexerATNSimulator.execATN(LexerATNSimulator.java:230)
    at org.antlr.v4.runtime.atn.LexerATNSimulator.match(LexerATNSimulator.java:114)
    at org.antlr.v4.runtime.Lexer.nextToken(Lexer.java:141)
    at org.antlr.v4.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:169)
    at org.antlr.v4.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:152)
    at org.antlr.v4.runtime.BufferedTokenStream.setup(BufferedTokenStream.java:254)
    at org.antlr.v4.runtime.BufferedTokenStream.lazyInit(BufferedTokenStream.java:249)
    at org.antlr.v4.runtime.CommonTokenStream.LT(CommonTokenStream.java:92)
    at org.antlr.v4.runtime.Parser.enterRule(Parser.java:628)
    at org.perses.grammar.c.PnfCParser.translationUnit(PnfCParser.java:7061)
    at org.perses.grammar.c.PnfCParserFacade.startParsing(PnfCParserFacade.java:48)
    at org.perses.grammar.c.PnfCParserFacade.startParsing(PnfCParserFacade.java:25)
    at org.perses.grammar.AbstractDefaultParserFacade$parseReader$3.apply(AbstractDefaultParserFacade.kt:70)
    at org.perses.grammar.AbstractDefaultParserFacade$parseReader$3.apply(AbstractDefaultParserFacade.kt:65)
    at org.perses.grammar.AbstractDefaultParserFacade$Companion.parseReader(AbstractDefaultParserFacade.kt:151)
    at org.perses.grammar.AbstractDefaultParserFacade.parseReader(AbstractDefaultParserFacade.kt:65)
    at org.perses.grammar.AbstractParserFacade.parseString(AbstractParserFacade.kt:86)
    at org.perses.grammar.AbstractParserFacade.parseString$default(AbstractParserFacade.kt:84)
    at org.perses.reduction.AbstractProgramReductionDriver$Companion.createSparTree(AbstractProgramReductionDriver.kt:607)
    at org.perses.reduction.RegularProgramReductionDriver$Companion.create(RegularProgramReductionDriver.kt:116)
    at org.perses.Main.createReductionDriver(Main.kt:81)
    at org.perses.AbstractMain.internalRun(AbstractMain.kt:33)
    at org.perses.util.cmd.AbstractMain.run(AbstractMain.kt:53)
    at org.perses.Main$Companion.main(Main.kt:87)
    at org.perses.Main.main(Main.kt)
chengniansun commented 11 months ago

This is because preprocessor macros are not a part of the c language.