Skip to content

Commit 205f7ee

Browse files
committed
[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.
1 parent df5840f commit 205f7ee

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/lib/Analysis/Lint.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ void Lint::visitCallBase(CallBase &I) {
244244
// dereferenced anyway.
245245
if (I.doesNotAccessMemory(ArgNo))
246246
continue;
247-
if (AI != BI && (*BI)->getType()->isPointerTy()) {
247+
if (AI != BI && (*BI)->getType()->isPointerTy() &&
248+
!isa<ConstantPointerNull>(*BI)) {
248249
AliasResult Result = AA->alias(*AI, *BI);
249250
Check(Result != AliasResult::MustAlias &&
250251
Result != AliasResult::PartialAlias,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt < %s -passes=lint -disable-output 2>&1 | FileCheck --allow-empty %s
2+
3+
declare void @foo(ptr noalias, ptr noalias)
4+
5+
define void @test() {
6+
entry:
7+
call void @foo(ptr null, ptr null)
8+
ret void
9+
}
10+
11+
; Lint should not complain about passing null to both arguments if they are
12+
; null, since noalias only applies if the argument is written to, which is not
13+
; possible for a null pointer.
14+
; CHECK-NOT: Unusual: noalias argument aliases another argument

0 commit comments

Comments
 (0)