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.
This commit is contained in:
Alex Lin 2018-04-23 16:40:32 -05:00
parent c44239a382
commit f412125715
2 changed files with 31 additions and 4 deletions

View File

@ -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") ) {

View File

@ -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() ;