Reapply "[Attributor][FIX] Allow negative offsets for ranges"
authorJohannes Doerfert <johannes@jdoerfert.de>
Sat, 17 Dec 2022 21:15:43 +0000 (13:15 -0800)
committerJohannes Doerfert <johannes@jdoerfert.de>
Mon, 19 Dec 2022 19:55:50 +0000 (11:55 -0800)
This reverts commit d57a3443f3e2b423fd7f5402f017dc7c0dff8cdf.

This patch was never part of the memory leak problem that lead to the
revert, just an innocent bystander caught in the middle...

Also, added a second reproducer reported after the revert.

llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/test/Transforms/Attributor/reduced/assertion_unassigned_range.ll [new file with mode: 0644]

index 52cfb40..59a0d2a 100644 (file)
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Transforms/Utils/CallGraphUpdater.h"
 
+#include <limits>
 #include <map>
 #include <optional>
 
@@ -274,11 +275,13 @@ struct RangeTy {
   }
 
   /// Constants used to represent special offsets or sizes.
-  /// - This assumes that Offset and Size are non-negative.
+  /// - We cannot assume that Offsets and Size are non-negative.
   /// - The constants should not clash with DenseMapInfo, such as EmptyKey
   ///   (INT64_MAX) and TombstoneKey (INT64_MIN).
-  static constexpr int64_t Unassigned = -1;
-  static constexpr int64_t Unknown = -2;
+  /// We use values "in the middle" of the 64 bit range to represent these
+  /// special cases.
+  static constexpr int64_t Unassigned = std::numeric_limits<int32_t>::min();
+  static constexpr int64_t Unknown = std::numeric_limits<int32_t>::max();
 };
 
 inline raw_ostream &operator<<(raw_ostream &OS, const RangeTy &R) {
diff --git a/llvm/test/Transforms/Attributor/reduced/assertion_unassigned_range.ll b/llvm/test/Transforms/Attributor/reduced/assertion_unassigned_range.ll
new file mode 100644 (file)
index 0000000..c7c5e7d
--- /dev/null
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --check-attributes --check-globals
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
+
+define i1 @_ZNK6openmc4Cell16contains_complexENS_8PositionES1_i() {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define {{[^@]+}}@_ZNK6openmc4Cell16contains_complexENS_8PositionES1_i
+; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TOBOOL71:%.*]] = trunc i8 undef to i1
+; CHECK-NEXT:    ret i1 false
+;
+entry:
+  %stack = alloca [24 x i8], i32 0, align 1
+  %arrayidx70 = getelementptr [24 x i8], ptr %stack, i64 0, i64 -1
+  %0 = load i8, ptr %arrayidx70, align 1
+  %tobool71 = trunc i8 %0 to i1
+  ret i1 false
+}
+;.
+; CHECK: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind willreturn memory(none) }
+;.
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CGSCC: {{.*}}
+; TUNIT: {{.*}}