Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp =================================================================== --- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -588,7 +588,10 @@ // - Header files: run non-path-sensitive checks only. // - System headers: don't run any checks. SourceManager &SM = Ctx->getSourceManager(); - SourceLocation SL = SM.getExpansionLoc(D->getLocation()); + SourceLocation SL = D->hasBody() ? D->getBody()->getLocStart() + : D->getLocation(); + SL = SM.getExpansionLoc(SL); + if (!Opts->AnalyzeAll && !SM.isWrittenInMainFile(SL)) { if (SL.isInvalid() || SM.isInSystemHeader(SL)) return AM_None; Index: test/Analysis/test-include.h =================================================================== --- test/Analysis/test-include.h +++ test/Analysis/test-include.h @@ -0,0 +1,2 @@ +void test_01(int * data); +#define DIVXY(X,Y) X/Y Index: test/Analysis/test-include.c =================================================================== --- test/Analysis/test-include.c +++ test/Analysis/test-include.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s +#include "test-include.h" +#define DIVYX(X,Y) Y/X + +void test_01(int * data) { + data = 0; + *data = 1; // expected-warning{{Dereference of null pointer}} +} + +int test_02() { + int res = DIVXY(1,0); // expected-warning{{Division by zero}} + // expected-warning@-1{{division by zero is undefined}} + return res; +} + +int test_03() { + int res = DIVYX(0,1); // expected-warning{{Division by zero}} + // expected-warning@-1{{division by zero is undefined}} + return res; +} +