Grammar-Mutator icon indicating copy to clipboard operation
Grammar-Mutator copied to clipboard

Seems broken with latest AFL++ ?

Open 20urc3 opened this issue 1 year ago • 3 comments

/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/support/Any.h:125:51: error: self-comparison always evaluates to true [-Werror=tautological-compare]
  125 |     template<int N = 0, typename std::enable_if<N == N && std::is_nothrow_copy_constructible<T>::value, int>::type = 0>
      |                                                 ~~^~~~
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/support/Any.h:130:51: error: self-comparison always evaluates to true [-Werror=tautological-compare]
  130 |     template<int N = 0, typename std::enable_if<N == N && !std::is_nothrow_copy_constructible<T>::value, int>::type = 0>
      |                                                 ~~^~~~
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/tree/ParseTree.h:49:18: error: ‘virtual bool antlr4::tree::ParseTree::operator==(const antlr4::tree::ParseTree&) const’ was hidden [-Werror=overloaded-virtual=]
   49 |     virtual bool operator == (const ParseTree &other) const;
      |                  ^~~~~~~~
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/RuleContext.h:131:10: note:   by ‘bool antlr4::RuleContext::operator==(const antlr4::RuleContext&)’
  131 |     bool operator == (const RuleContext &other) { return this == &other; } // Simple address comparison.
      |          ^~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [Makefile:51: antlr4_shim.o] Error 1
make[2]: Leaving directory '/home/s0urc3/Downloads/Grammar-Mutator/lib/antlr4_shim'
make[1]: *** [Makefile:25: antlr4_shim] Error 2
make[1]: Leaving directory '/home/s0urc3/Downloads/Grammar-Mutator/lib'
make: *** [GNUmakefile:120: build_lib] Error 2

20urc3 avatar Oct 23 '24 19:10 20urc3

Maybe try either updating antlr4-cpp-runtime or disable these errors?

domenukk avatar Oct 23 '24 20:10 domenukk

Tried latest version of antlr4 and the one from the readme. Got this error again, which is weird bc it used to work perfectly fine

gnu++14 -fPIC -Wno-attributes -Wall -Wextra -Werror -O3 -o antlr4_shim.o -c antlr4_shim.cpp
In file included from /home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/tree/ParseTree.h:8,
                 from /home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/RuleContext.h:8,
                 from /home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/ParserRuleContext.h:8,
                 from /home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/InterpreterRuleContext.h:8,
                 from /home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/antlr4-runtime.h:30,
                 from antlr4_shim.cpp:21:
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/support/Any.h:125:51: error: self-comparison always evaluates to true [-Werror=tautological-compare]
  125 |     template<int N = 0, typename std::enable_if<N == N && std::is_nothrow_copy_constructible<T>::value, int>::type = 0>
      |                                                 ~~^~~~
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/support/Any.h:130:51: error: self-comparison always evaluates to true [-Werror=tautological-compare]
  130 |     template<int N = 0, typename std::enable_if<N == N && !std::is_nothrow_copy_constructible<T>::value, int>::type = 0>
      |                                                 ~~^~~~
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/tree/ParseTree.h:49:18: error: ‘virtual bool antlr4::tree::ParseTree::operator==(const antlr4::tree::ParseTree&) const’ was hidden [-Werror=overloaded-virtual=]
   49 |     virtual bool operator == (const ParseTree &other) const;
      |                  ^~~~~~~~
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/RuleContext.h:131:10: note:   by ‘bool antlr4::RuleContext::operator==(const antlr4::RuleContext&)’
  131 |     bool operator == (const RuleContext &other) { return this == &other; } // Simple address comparison.
      |          ^~~~~~~~
In file included from antlr4_shim.cpp:22:
./generated/GrammarLexer.h:263:16: error: ‘SerializedATNView’ in namespace ‘antlr4::atn’ does not name a type
  263 |   antlr4::atn::SerializedATNView getSerializedATN() const override;
      |                ^~~~~~~~~~~~~~~~~
In file included from antlr4_shim.cpp:23:
./generated/GrammarParser.h:256:64: error: ‘ParserATNSimulatorOptions’ in namespace ‘antlr4::atn’ does not name a type; did you mean ‘ParserATNSimulator’?
  256 |   GrammarParser(antlr4::TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options);
      |                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                ParserATNSimulator
./generated/GrammarParser.h:268:16: error: ‘SerializedATNView’ in namespace ‘antlr4::atn’ does not name a type
  268 |   antlr4::atn::SerializedATNView getSerializedATN() const override;
      |                ^~~~~~~~~~~~~~~~~
antlr4_shim.cpp: In function ‘tree_t* tree_from_buf(const uint8_t*, size_t)’:
antlr4_shim.cpp:84:22: error: cannot declare variable ‘lexer’ to be of abstract type ‘GrammarLexer’
   84 |     GrammarLexer     lexer(&input);
      |                      ^~~~~
./generated/GrammarLexer.h:12:8: note:   because the following virtual functions are pure within ‘GrammarLexer’:
   12 | class  GrammarLexer : public antlr4::Lexer {
      |        ^~~~~~~~~~~~
In file included from /home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/Lexer.h:8,
                 from /home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/antlr4-runtime.h:31:
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/Recognizer.h:28:45: note:     ‘virtual const std::vector<std::__cxx11::basic_string<char> >& antlr4::Recognizer::getTokenNames() const’
   28 |     virtual std::vector<std::string> const& getTokenNames() const = 0;
      |                                             ^~~~~~~~~~~~~
antlr4_shim.cpp:91:19: error: cannot declare variable ‘parser’ to be of abstract type ‘GrammarParser’
   91 |     GrammarParser parser(&tokens);
      |                   ^~~~~~
./generated/GrammarParser.h:12:8: note:   because the following virtual functions are pure within ‘GrammarParser’:
   12 | class  GrammarParser : public antlr4::Parser {
      |        ^~~~~~~~~~~~~
/home/s0urc3/Downloads/Grammar-Mutator/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/Recognizer.h:28:45: note:     ‘virtual const std::vector<std::__cxx11::basic_string<char> >& antlr4::Recognizer::getTokenNames() const’
   28 |     virtual std::vector<std::string> const& getTokenNames() const = 0;
      |                                             ^~~~~~~~~~~~~

20urc3 avatar Oct 25 '24 10:10 20urc3

I have three options to fix the broken build:

  1. Use an older compiler version
  2. Disable the -Werror flag in the build system
  3. Fix the root cause of the problem

1. Older Compiler

The build fails with g++-13 but succeeds with g++-11 (I haven't tested at other compilers). Install the older compiler and run the build:

apt install -y g++-11
mkdir build && cd build
cmake .. -DANTLR_JAR_LOCATION=/path/to/antlr-4.8-complete.jar -DGRAMMAR_FILE=/path/to/Grammar-Mutator/grammars/ruby.json -DCMAKE_CXX_COMPILER=g++-11
cmake --build .

2. Disabling -Werror flag

  1. Create a file named disable_Werror.patch with the following content:
    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index c94eba0..32ba7cf 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -49,7 +49,7 @@ endif ()
    
    # Set -Wall -Wextra -Werror
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
    -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
    +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
    
    # Do not disable assertions based on CMAKE_BUILD_TYPE.
    foreach (_build_type "Release" "MinSizeRel" "RelWithDebInfo")
    
  2. Apply the patch:
    git apply disable_Werror.patch
    
  3. Build the project:
    mkdir build && cd build
    cmake .. -DANTLR_JAR_LOCATION=/path/to/antlr-4.8-complete.jar -DGRAMMAR_FILE=/path/to/Grammar-Mutator/grammars/ruby.json
    cmake --build .
    

3. Fix the Root Cause

A Pull Request with the fixes has been created, but it is unlikely to be accepted: PR with fixes. Therefore, here are the instructions to apply the fixes manually:

  1. Start build the project:

    mkdir build && cd build
    cmake .. -DANTLR_JAR_LOCATION=/path/to/antlr-4.8-complete.jar -DGRAMMAR_FILE=/path/to/Grammar-Mutator/grammars/ruby.json
    cmake --build .
    

    * After some time, the build error will appear *

  2. Make changes to build/third_party/antlr4-cpp-runtime/antlr4-cpp-runtime-src/runtime/src/RuleContext.h:

    diff --git a/runtime/src/RuleContext.h b/runtime/src/RuleContext.h
    index 9ee0d2d..9de977a 100755
    --- a/runtime/src/RuleContext.h
    +++ b/runtime/src/RuleContext.h
    @@ -128,6 +128,7 @@ namespace antlr4 {
    
        virtual std::string toString(const std::vector<std::string> &ruleNames, RuleContext *stop);
    
    +    using ParseTree::operator==;
        bool operator == (const RuleContext &other) { return this == &other; } // Simple address comparison.
    
    private:
    
  3. Continue the build with the changes applied:

    cmake --build .
    

strongHunter avatar Feb 02 '25 11:02 strongHunter