From f412125715dfc8b59f373e057fc8e1e948989ee4 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Mon, 23 Apr 2018 16:40:32 -0500 Subject: [PATCH] Is Trick ICG missing some uses of TRICK_ICG #608 Yes, it is, it's missing all of them. Any clang/llvm version 3.5 and above. So it's been broken for a while. We inherit from a clang class that processes preprocessing statements. If we override virtual functions of a certain signature, we can inject our code into the preprocessing process. In this case we're looking for the use of TRICK_ICG. Clang changed the function signature in version 3.5. From 3.5 on our functions were never called, so we never would find TRICK_ICG. I created new signatures for the functions post 3.5 so they will work again. --- .../Interface_Code_Gen/FindTrickICG.cpp | 28 ++++++++++++++++--- .../Interface_Code_Gen/FindTrickICG.hh | 7 +++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp b/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp index 9f3d5a42..082aeb1d 100644 --- a/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp @@ -35,7 +35,12 @@ void FindTrickICG::FileChanged(clang::SourceLocation Loc, FileChangeReason Reaso } } -void FindTrickICG::If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) { +#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) +void FindTrickICG::If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) +#else +void FindTrickICG::If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) +#endif +{ if ( ConditionRange.isValid() ) { // Get the full text of the if statement into a string clang::FullSourceLoc fsl_begin(ConditionRange.getBegin() , ci.getSourceManager()) ; @@ -67,12 +72,22 @@ void FindTrickICG::If(clang::SourceLocation Loc, clang::SourceRange ConditionRan } } -void FindTrickICG::ElIf(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) { +#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) +void FindTrickICG::ElIf(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) +#else +void FindTrickICG::ElIf(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) +#endif +{ // Do the same processing for an #elif statement as an #if statement. If(Loc,ConditionRange,ConditionValue) ; } -void FindTrickICG::Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) { +#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) +void FindTrickICG::Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) +#else +void FindTrickICG::Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) +#endif +{ // Get the token name that is being tested. std::string name = MacroNameTok.getIdentifierInfo()->getName().str() ; if ( ! name.compare("TRICK_ICG") ) { @@ -94,7 +109,12 @@ void FindTrickICG::Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNam } -void FindTrickICG::Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) { +#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) +void FindTrickICG::Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) +#else +void FindTrickICG::Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) +#endif +{ // Get the token name that is being tested. std::string name = MacroNameTok.getIdentifierInfo()->getName().str() ; if ( ! name.compare("TRICK_ICG") ) { diff --git a/trick_source/codegen/Interface_Code_Gen/FindTrickICG.hh b/trick_source/codegen/Interface_Code_Gen/FindTrickICG.hh index 57cf6455..ae9034ab 100644 --- a/trick_source/codegen/Interface_Code_Gen/FindTrickICG.hh +++ b/trick_source/codegen/Interface_Code_Gen/FindTrickICG.hh @@ -21,10 +21,17 @@ class FindTrickICG : public clang::PPCallbacks { clang::FileID PrevFID = clang::FileID()) ; // callbacks called when the preprocessor directives of types are processed. +#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) + virtual void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) ; + virtual void ElIf(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) ; + virtual void Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) ; + virtual void Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) ; +#else virtual void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) ; virtual void ElIf(clang::SourceLocation Loc, clang::SourceRange ConditionRange, bool ConditionValue) ; virtual void Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) ; virtual void Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDirective *MD) ; +#endif // print a warning about using TRICK_ICG. void print_header() ;