aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2013-01-23 05:08:29 +0000
committerNick Lewycky <nicholas@mxc.ca>2013-01-23 05:08:29 +0000
commit3edf387e4338ff98d9874b4c1b41d787e49d6c2b (patch)
tree7b7559d413384a092cfa3ef7cc985c698d58d2c1 /lib/Sema/SemaChecking.cpp
parentd069c3d9cb8e858d3cb28e4d0a99a086c38453c5 (diff)
Make __attribute__((nonnull)) use the general expression evaluator to search for
nulls instead of limiting itself to the language-defined "null pointer constant". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173227 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 3d4c5d3a27..0d8f764df5 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -1837,8 +1837,20 @@ Sema::CheckNonNullArguments(const NonNullAttr *NonNull,
e = NonNull->args_end();
i != e; ++i) {
const Expr *ArgExpr = ExprArgs[*i];
- if (ArgExpr->isNullPointerConstant(Context,
- Expr::NPC_ValueDependentIsNotNull))
+
+ // As a special case, transparent unions initialized with zero are
+ // considered null for the purposes of the nonnull attribute.
+ if (const RecordType *UT = ArgExpr->getType()->getAsUnionType()) {
+ if (UT->getDecl()->hasAttr<TransparentUnionAttr>())
+ if (const CompoundLiteralExpr *CLE =
+ dyn_cast<CompoundLiteralExpr>(ArgExpr))
+ if (const InitListExpr *ILE =
+ dyn_cast<InitListExpr>(CLE->getInitializer()))
+ ArgExpr = ILE->getInit(0);
+ }
+
+ bool Result;
+ if (ArgExpr->EvaluateAsBooleanCondition(Result, Context) && !Result)
Diag(CallSiteLoc, diag::warn_null_arg) << ArgExpr->getSourceRange();
}
}