Skip to content

Commit

Permalink
Merge pull request #61 from pmartin210/partial-macro
Browse files Browse the repository at this point in the history
Partial macro detection for macro as argument to macro
  • Loading branch information
dbeer1 authored May 3, 2021
2 parents 8d4c06d + 9f2fb93 commit 7d4c45b
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/source_util.cpp
Original file line number Diff line number Diff line change
@@ -187,6 +187,13 @@ bool SourceUtil::isPartialMacro(const clang::SourceRange &sourceRange,
// the statement.

clang::SourceLocation begin = sourceRange.getBegin();
clang::SourceLocation end = sourceRange.getEnd();

if (sourceManager.isMacroArgExpansion(begin) !=
sourceManager.isMacroArgExpansion(end)) {
// This catches macros which might receive other macros as arguments
return true; // partial macro
}

auto usesGccVarargExtensionAtLoc = [&sourceManager,
&preprocessor](const auto &loc) {
@@ -242,7 +249,6 @@ bool SourceUtil::isPartialMacro(const clang::SourceRange &sourceRange,
// Trace through levels of macros that are expanded by the end of the
// statement.

clang::SourceLocation end = sourceRange.getEnd();
const clang::MacroInfo *prevMacro = nullptr;

while (end.isMacroID()) {
Original file line number Diff line number Diff line change
@@ -43,7 +43,8 @@ int positive()
+ AFTER_EXPR(4)
+ OUTER_MACRO(6)
+ VARARG_TO_VARARG_PASTED(0, 1, M_ARRAY[1])
+ VARARG_TO_NONVARARG_PASTED(M_ARRAY[1]);
+ VARARG_TO_NONVARARG_PASTED(M_ARRAY[1])
+ MACRO_AS_ARG(M_ARRAY);
}

int negative() {
@@ -60,7 +61,3 @@ int negative() {
+ VARARG_TO_NONVARARG_DIRECT(M_ARRAY[1]);

}

int falseNegative() {
return MACRO_AS_ARG(M_ARRAY);
}

0 comments on commit 7d4c45b

Please sign in to comment.