r216574 - Fix regression in r216520: don't apply nonnull to non-pointer function
Richard Smith
richard-llvm at metafoo.co.uk
Wed Aug 27 11:56:18 PDT 2014
Author: rsmith
Date: Wed Aug 27 13:56:18 2014
New Revision: 216574
URL: http://llvm.org/viewvc/llvm-project?rev=216574&view=rev
Log:
Fix regression in r216520: don't apply nonnull to non-pointer function
parameters in the IR.
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/test/CodeGen/nonnull.c
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=216574&r1=216573&r2=216574&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Aug 27 13:56:18 2014
@@ -1557,8 +1557,17 @@ void CodeGenFunction::EmitFunctionProlog
llvm::Value *V = AI;
if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
- if ((NNAtt && NNAtt->isNonNull(PVD->getFunctionScopeIndex())) ||
- PVD->hasAttr<NonNullAttr>())
+ // FIXME: __attribute__((nonnull)) can also be applied to:
+ // - references to pointers, where the pointee is known to be
+ // nonnull (apparently a Clang extension)
+ // - transparent unions containing pointers
+ // In the former case, LLVM IR cannot represent the constraint. In
+ // the latter case, we have no guarantee that the transparent union
+ // is in fact passed as a pointer.
+ if (((NNAtt && NNAtt->isNonNull(PVD->getFunctionScopeIndex())) ||
+ PVD->hasAttr<NonNullAttr>()) &&
+ (PVD->getType()->isAnyPointerType() ||
+ PVD->getType()->isBlockPointerType()))
AI->addAttr(llvm::AttributeSet::get(getLLVMContext(),
AI->getArgNo() + 1,
llvm::Attribute::NonNull));
Modified: cfe/trunk/test/CodeGen/nonnull.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/nonnull.c?rev=216574&r1=216573&r2=216574&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/nonnull.c (original)
+++ cfe/trunk/test/CodeGen/nonnull.c Wed Aug 27 13:56:18 2014
@@ -21,3 +21,23 @@ int * bar3() __attribute__((returns_nonn
return &a;
}
+// CHECK: define i32 @bar4(i32 %n, i32* nonnull %p)
+int bar4(int n, int *p) __attribute__((nonnull)) {
+ return n + *p;
+}
+
+// CHECK: define i32 @bar5(i32 %n, i32* nonnull %p)
+int bar5(int n, int *p) __attribute__((nonnull(1, 2))) {
+ return n + *p;
+}
+
+typedef union {
+ unsigned long long n;
+ int *p;
+ double d;
+} TransparentUnion __attribute__((transparent_union));
+
+// CHECK: define i32 @bar6(i64 %
+int bar6(TransparentUnion tu) __attribute__((nonnull(1))) {
+ return *tu.p;
+}
More information about the cfe-commits
mailing list