[PATCH] D135262: [SimplifyLibCalls] Pre-commit test case showing bug with wide char support

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 06:29:52 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG3f3018b602c2: [SimplifyLibCalls] Pre-commit test case showing bug with wide char support (authored by bjope).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135262/new/

https://reviews.llvm.org/D135262

Files:
  llvm/test/Transforms/InstCombine/wcslen-1.ll


Index: llvm/test/Transforms/InstCombine/wcslen-1.ll
===================================================================
--- llvm/test/Transforms/InstCombine/wcslen-1.ll
+++ llvm/test/Transforms/InstCombine/wcslen-1.ll
@@ -214,4 +214,45 @@
   ret i64 %l
 }
 
+ at ws = constant [10 x i32] [i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0]
+
+; Fold wcslen(ws + 2) => 7.
+; FIXME: This fold is faulty, result should be 7 not 1.
+define i64 @fold_wcslen_1() {
+; CHECK-LABEL: @fold_wcslen_1(
+; CHECK-NEXT:    ret i64 1
+;
+  %p = getelementptr inbounds [10 x i32], ptr @ws, i64 0, i64 2
+  %len = tail call i64 @wcslen(ptr %p)
+  ret i64 %len
+}
+
+; Should not crash on this, and no optimization expected (idea is to get into
+; llvm::getConstantDataArrayInfo looking for an array with 32-bit elements but
+; with an offset that isn't a multiple of the element size).  FIXME: Looks a
+; bit weird. Don't think we should return 6 here.
+define i64 @no_fold_wcslen_1() {
+; CHECK-LABEL: @no_fold_wcslen_1(
+; CHECK-NEXT:    ret i64 6
+;
+  %p = getelementptr [15 x i8], ptr @ws, i64 0, i64 3
+  %len = tail call i64 @wcslen(ptr %p)
+  ret i64 %len
+}
+
+ at s8 = constant [10 x i8] [i8 9, i8 8, i8 7, i8 6, i8 5, i8 4, i8 3, i8 2, i8 1, i8 0]
+
+; Should not crash on this, and no optimization expected (idea is to get into
+; llvm::getConstantDataArrayInfo looking for an array with 32-bit elements but
+; with an offset that isn't a multiple of the element size).
+define i64 @no_fold_wcslen_2() {
+; CHECK-LABEL: @no_fold_wcslen_2(
+; CHECK-NEXT:    %len = tail call i64 @wcslen(ptr nonnull getelementptr inbounds ([10 x i8], ptr @s8, i64 0, i64 3))
+; CHECK-NEXT:    ret i64 %len
+;
+  %p = getelementptr [10 x i8], ptr @s8, i64 0, i64 3
+  %len = tail call i64 @wcslen(ptr %p)
+  ret i64 %len
+}
+
 attributes #0 = { null_pointer_is_valid }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135262.466061.patch
Type: text/x-patch
Size: 1858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221007/1c2b32a1/attachment.bin>


More information about the llvm-commits mailing list