From c90681b681a7a45cf5bf515d1904e2015f7ed524 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Thu, 2 Jan 2020 16:41:17 -0600 Subject: [PATCH] [Attributor][FIX] Don't crash on ptr2int/int2ptr instructions An integer isn't allowed in getAlignmentForValue so we need to stop at a ptr2int instruction during exploration. --- llvm/lib/Transforms/IPO/Attributor.cpp | 3 ++- llvm/test/Transforms/Attributor/align.ll | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 2655930aec57..46664d627699 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -3466,7 +3466,8 @@ static unsigned int getKnownAlignForUse(Attributor &A, // We need to follow common pointer manipulation uses to the accesses they // feed into. if (isa(I)) { - TrackUse = true; + // Follow all but ptr2int casts. + TrackUse = !isa(I); return 0; } if (auto *GEP = dyn_cast(I)) { diff --git a/llvm/test/Transforms/Attributor/align.ll b/llvm/test/Transforms/Attributor/align.ll index 6f955be467bf..f01ae28431d6 100644 --- a/llvm/test/Transforms/Attributor/align.ll +++ b/llvm/test/Transforms/Attributor/align.ll @@ -398,5 +398,15 @@ define void @test12-6(i32* align 4 %p) { ret void } +; Don't crash on ptr2int/int2ptr uses. +define i64 @ptr2int(i32* %p) { + %p2i = ptrtoint i32* %p to i64 + ret i64 %p2i +} +define i64* @int2ptr(i64 %i) { + %i2p = inttoptr i64 %i to i64* + ret i64* %i2p +} + attributes #0 = { nounwind uwtable noinline } attributes #1 = { uwtable noinline }