[llvm] 205f7ee - [Lint] Skip null args when checking noalias
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 06:03:01 PDT 2024
Author: Nikita Popov
Date: 2024-09-04T15:02:50+02:00
New Revision: 205f7ee737f75e666f70ad51bda5f778c02ab124
URL: https://github.com/llvm/llvm-project/commit/205f7ee737f75e666f70ad51bda5f778c02ab124
DIFF: https://github.com/llvm/llvm-project/commit/205f7ee737f75e666f70ad51bda5f778c02ab124.diff
LOG: [Lint] Skip null args when checking noalias
Do not emit a warning if there are two null noalias arguments,
as they cannot be dereferenced anyway.
This is a common pattern for `@.omp_outlined`, which has some
optional noalias arguments.
Added:
llvm/test/Analysis/Lint/noalias-null.ll
Modified:
llvm/lib/Analysis/Lint.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index 00e430ce8e0ab2..e0a029802bbd9a 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -244,7 +244,8 @@ void Lint::visitCallBase(CallBase &I) {
// dereferenced anyway.
if (I.doesNotAccessMemory(ArgNo))
continue;
- if (AI != BI && (*BI)->getType()->isPointerTy()) {
+ if (AI != BI && (*BI)->getType()->isPointerTy() &&
+ !isa<ConstantPointerNull>(*BI)) {
AliasResult Result = AA->alias(*AI, *BI);
Check(Result != AliasResult::MustAlias &&
Result != AliasResult::PartialAlias,
diff --git a/llvm/test/Analysis/Lint/noalias-null.ll b/llvm/test/Analysis/Lint/noalias-null.ll
new file mode 100644
index 00000000000000..5d2ecb5da5898e
--- /dev/null
+++ b/llvm/test/Analysis/Lint/noalias-null.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -passes=lint -disable-output 2>&1 | FileCheck --allow-empty %s
+
+declare void @foo(ptr noalias, ptr noalias)
+
+define void @test() {
+entry:
+ call void @foo(ptr null, ptr null)
+ ret void
+}
+
+; Lint should not complain about passing null to both arguments if they are
+; null, since noalias only applies if the argument is written to, which is not
+; possible for a null pointer.
+; CHECK-NOT: Unusual: noalias argument aliases another argument
More information about the llvm-commits
mailing list