r212874 - Add nonnull in CodeGen for __attribute__((returns_nonnull))
Hal Finkel
hfinkel at anl.gov
Fri Jul 11 21:51:06 PDT 2014
Author: hfinkel
Date: Fri Jul 11 23:51:04 2014
New Revision: 212874
URL: http://llvm.org/viewvc/llvm-project?rev=212874&view=rev
Log:
Add nonnull in CodeGen for __attribute__((returns_nonnull))
As a follow-up to r212835, also add the LLVM nonnull function attribute when
__attribute__((returns_nonnull)) is provided.
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=212874&r1=212873&r2=212874&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Jul 11 23:51:04 2014
@@ -1107,6 +1107,8 @@ void CodeGenModule::ConstructAttributeLi
}
if (TargetDecl->hasAttr<MallocAttr>())
RetAttrs.addAttribute(llvm::Attribute::NoAlias);
+ if (TargetDecl->hasAttr<ReturnsNonNullAttr>())
+ RetAttrs.addAttribute(llvm::Attribute::NonNull);
}
if (CodeGenOpts.OptimizeSize)
Modified: cfe/trunk/test/CodeGen/nonnull.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/nonnull.c?rev=212874&r1=212873&r2=212874&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/nonnull.c (original)
+++ cfe/trunk/test/CodeGen/nonnull.c Fri Jul 11 23:51:04 2014
@@ -15,3 +15,9 @@ void bar2(int * x, int * y) __attribute_
*x = 0;
}
+static int a;
+// CHECK: define nonnull i32* @bar3()
+int * bar3() __attribute__((returns_nonnull)) {
+ return &a;
+}
+
More information about the cfe-commits
mailing list