ASTContext &getASTContext() {
return Eng.getContext();
}
-
+
+ const LangOptions &getLangOptions() const {
+ return Eng.getContext().getLangOptions();
+ }
+
const LocationContext *getLocationContext() const {
return Pred->getLocationContext();
}
/// function with the given name.
bool isCLibraryFunction(const FunctionDecl *FD, StringRef Name);
+ /// \brief Depending on wither the location corresponds to a macro, return
+ /// either the macro name or the token spelling.
+ ///
+ /// This could be useful when checkers' logic depends on whether a function
+ /// is called with a given macro argument. For example:
+ /// s = socket(AF_INET,..)
+ /// If AF_INET is a macro, the result should be treated as a source of taint.
+ ///
+ /// \sa clang::Lexer::getSpelling(), clang::Lexer::getImmediateMacroName().
+ StringRef getMacroNameOrSpelling(SourceLocation &Loc);
+
private:
ExplodedNode *addTransitionImpl(const ProgramState *State,
bool MarkAsSink,
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/Basic/Builtins.h"
+#include "clang/Lex/Lexer.h"
using namespace clang;
using namespace ento;
return false;
}
+
+StringRef CheckerContext::getMacroNameOrSpelling(SourceLocation &Loc) {
+ if (!Loc.isMacroID()) {
+ SmallVector<char, 16> buf;
+ return Lexer::getSpelling(Loc, buf, getSourceManager(), getLangOptions());
+ } else {
+ return Lexer::getImmediateMacroName(Loc, getSourceManager(),
+ getLangOptions());
+ }
+ return StringRef();
+}
+