Skip to content

Commit

Permalink
Is Trick ICG missing some uses of TRICK_ICG #608
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexlin0 committed Apr 23, 2018
1 parent c44239a commit f412125
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
28 changes: 24 additions & 4 deletions trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ;
Expand Down Expand Up @@ -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") ) {
Expand All @@ -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") ) {
Expand Down
7 changes: 7 additions & 0 deletions trick_source/codegen/Interface_Code_Gen/FindTrickICG.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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() ;
Expand Down

0 comments on commit f412125

Please sign in to comment.