diff options
author | David Blaikie <dblaikie@gmail.com> | 2012-03-16 20:30:12 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2012-03-16 20:30:12 +0000 |
commit | b1360498b0c0794fd7925f4bdac68ae91ff7493b (patch) | |
tree | 2567be212551dedb8be69024e2c2b19707947a01 /lib/Sema/SemaChecking.cpp | |
parent | 9c6fde5ac9c4a696baaa637a7fb6d83fe91e1e09 (diff) |
Suppress macro expansion of NULL in NULL warnings.
For "int i = NULL;" we would produce:
null.cpp:5:11: warning: implicit conversion of NULL constant to integer [-Wconversion]
int i = NULL;
~ ^~~~
null.cpp:1:14: note: expanded from macro 'NULL'
\#define NULL __null
^~~~~~
But we really shouldn't trace that macro expansion back into the header, yet we
still want macro back traces for code like this:
\#define FOO NULL
int i = FOO;
or
\#define FOO int i = NULL;
FOO
While providing appropriate tagging at different levels of the expansion, etc.
The included test case exercises these cases & does some basic validation (to
ensure we don't have macro expansion notes where we shouldn't, and do where we
should) - but doesn't go as far as to validate the source location/ranges
used in those notes and warnings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152940 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index cd24a4f459..7ab05c41f7 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4075,8 +4075,11 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T, if ((E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull) == Expr::NPCK_GNUNull) && Target->isIntegerType()) { - S.Diag(E->getExprLoc(), diag::warn_impcast_null_pointer_to_integer) - << T << E->getSourceRange() << clang::SourceRange(CC); + SourceLocation Loc = E->getSourceRange().getBegin(); + if (Loc.isMacroID()) + Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first; + S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer) + << T << Loc << clang::SourceRange(CC); return; } |