Skip to content

Commit 1e64ea9

Browse files
committed
Revert "[CaptureTracking][FunctionAttrs] Add support for CaptureInfo (#125880)"
This reverts commit ee655ca. A miscompilation has been reported at: #125880 (comment)
1 parent 43780f4 commit 1e64ea9

25 files changed

+238
-511
lines changed

clang/test/CodeGen/allow-ubsan-check.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int div(int x, int y) {
8686
}
8787

8888
// CHECK-LABEL: define dso_local i32 @null(
89-
// CHECK-SAME: ptr noundef readonly captures(address_is_null) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
89+
// CHECK-SAME: ptr noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
9090
// CHECK-NEXT: [[ENTRY:.*:]]
9191
// CHECK-NEXT: [[TMP0:%.*]] = icmp eq ptr [[X]], null, !nosanitize [[META2]]
9292
//
@@ -102,7 +102,7 @@ int div(int x, int y) {
102102
// CHECK-NEXT: ret i32 [[TMP2]]
103103
//
104104
// TR-LABEL: define dso_local i32 @null(
105-
// TR-SAME: ptr noundef readonly captures(address_is_null) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
105+
// TR-SAME: ptr noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
106106
// TR-NEXT: [[ENTRY:.*:]]
107107
// TR-NEXT: [[TMP0:%.*]] = icmp eq ptr [[X]], null, !nosanitize [[META2]]
108108
// TR-NEXT: [[TMP1:%.*]] = tail call i1 @llvm.allow.ubsan.check(i8 29), !nosanitize [[META2]]
@@ -116,7 +116,7 @@ int div(int x, int y) {
116116
// TR-NEXT: ret i32 [[TMP2]]
117117
//
118118
// REC-LABEL: define dso_local i32 @null(
119-
// REC-SAME: ptr noundef readonly captures(address_is_null) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
119+
// REC-SAME: ptr noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
120120
// REC-NEXT: [[ENTRY:.*:]]
121121
// REC-NEXT: [[TMP0:%.*]] = icmp eq ptr [[X]], null, !nosanitize [[META2]]
122122
// REC-NEXT: [[TMP1:%.*]] = tail call i1 @llvm.allow.ubsan.check(i8 29), !nosanitize [[META2]]

clang/test/CodeGenCXX/RelativeVTablesABI/dynamic-cast.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O3 -o - -emit-llvm | FileCheck %s
55

6-
// CHECK: define{{.*}} ptr @_Z6upcastP1B(ptr noundef readnone returned captures(ret: address, provenance) %b) local_unnamed_addr
6+
// CHECK: define{{.*}} ptr @_Z6upcastP1B(ptr noundef readnone returned %b) local_unnamed_addr
77
// CHECK-NEXT: entry:
88
// CHECK-NEXT: ret ptr %b
99
// CHECK-NEXT: }
@@ -22,12 +22,12 @@
2222

2323
// CHECK: declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) local_unnamed_addr
2424

25-
// CHECK: define{{.*}} ptr @_Z8selfcastP1B(ptr noundef readnone returned captures(ret: address, provenance) %b) local_unnamed_addr
25+
// CHECK: define{{.*}} ptr @_Z8selfcastP1B(ptr noundef readnone returned %b) local_unnamed_addr
2626
// CHECK-NEXT: entry
2727
// CHECK-NEXT: ret ptr %b
2828
// CHECK-NEXT: }
2929

30-
// CHECK: define{{.*}} ptr @_Z9void_castP1B(ptr noundef readonly captures(address_is_null, ret: address, provenance) %b) local_unnamed_addr
30+
// CHECK: define{{.*}} ptr @_Z9void_castP1B(ptr noundef readonly %b) local_unnamed_addr
3131
// CHECK-NEXT: entry:
3232
// CHECK-NEXT: [[isnull:%[0-9]+]] = icmp eq ptr %b, null
3333
// CHECK-NEXT: br i1 [[isnull]], label %[[dynamic_cast_end:[a-z0-9._]+]], label %[[dynamic_cast_notnull:[a-z0-9._]+]]

clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// CHECK-NEXT: ret ptr @_ZTS1A
2525
// CHECK-NEXT: }
2626

27-
// CHECK: define{{.*}} i1 @_Z5equalP1A(ptr noundef readonly captures(address_is_null) %a) local_unnamed_addr
27+
// CHECK: define{{.*}} i1 @_Z5equalP1A(ptr noundef readonly %a) local_unnamed_addr
2828
// CHECK-NEXT: entry:
2929
// CHECK-NEXT: [[isnull:%[0-9]+]] = icmp eq ptr %a, null
3030
// CHECK-NEXT: br i1 [[isnull]], label %[[bad_typeid:[a-z0-9._]+]], label %[[end:[a-z0-9.+]+]]

clang/test/CodeGenOpenCL/amdgcn-buffer-rsrc-type.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ __amdgpu_buffer_rsrc_t getBuffer(void *p) {
2222
}
2323

2424
// CHECK-LABEL: define {{[^@]+}}@consumeBufferPtr
25-
// CHECK-SAME: (ptr addrspace(5) noundef readonly captures(address) [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
25+
// CHECK-SAME: (ptr addrspace(5) noundef readonly [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
2626
// CHECK-NEXT: entry:
2727
// CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq ptr addrspace(5) [[P]], addrspacecast (ptr null to ptr addrspace(5))
2828
// CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
@@ -39,7 +39,7 @@ void consumeBufferPtr(__amdgpu_buffer_rsrc_t *p) {
3939
}
4040

4141
// CHECK-LABEL: define {{[^@]+}}@test
42-
// CHECK-SAME: (ptr addrspace(5) noundef readonly captures(address) [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
42+
// CHECK-SAME: (ptr addrspace(5) noundef readonly [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
4343
// CHECK-NEXT: entry:
4444
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[A]], align 16, !tbaa [[TBAA8:![0-9]+]]
4545
// CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[TMP0]], 0

clang/test/CodeGenOpenCL/as_type.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int3 f8(char16 x) {
6767
return __builtin_astype(x, int3);
6868
}
6969

70-
//CHECK: define{{.*}} spir_func noundef ptr addrspace(1) @addr_cast(ptr noundef readnone captures(ret: address, provenance) %[[x:.*]])
70+
//CHECK: define{{.*}} spir_func noundef ptr addrspace(1) @addr_cast(ptr noundef readnone %[[x:.*]])
7171
//CHECK: %[[cast:.*]] ={{.*}} addrspacecast ptr %[[x]] to ptr addrspace(1)
7272
//CHECK: ret ptr addrspace(1) %[[cast]]
7373
global int* addr_cast(int *x) {

llvm/include/llvm/Analysis/CaptureTracking.h

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
#define LLVM_ANALYSIS_CAPTURETRACKING_H
1515

1616
#include "llvm/ADT/DenseMap.h"
17-
#include "llvm/Support/ModRef.h"
1817

1918
namespace llvm {
2019

2120
class Value;
2221
class Use;
23-
class CaptureInfo;
2422
class DataLayout;
2523
class Instruction;
2624
class DominatorTree;
@@ -79,47 +77,10 @@ namespace llvm {
7977
const DominatorTree &DT,
8078
unsigned MaxUsesToExplore = 0);
8179

82-
/// Capture information for a specific Use.
83-
struct UseCaptureInfo {
84-
/// Components captured by this use.
85-
CaptureComponents UseCC;
86-
/// Components captured by the return value of the user of this Use.
87-
CaptureComponents ResultCC;
88-
89-
UseCaptureInfo(CaptureComponents UseCC,
90-
CaptureComponents ResultCC = CaptureComponents::None)
91-
: UseCC(UseCC), ResultCC(ResultCC) {}
92-
93-
static UseCaptureInfo passthrough() {
94-
return UseCaptureInfo(CaptureComponents::None, CaptureComponents::All);
95-
}
96-
97-
bool isPassthrough() const {
98-
return capturesNothing(UseCC) && capturesAnything(ResultCC);
99-
}
100-
101-
operator CaptureComponents() const { return UseCC | ResultCC; }
102-
};
103-
10480
/// This callback is used in conjunction with PointerMayBeCaptured. In
10581
/// addition to the interface here, you'll need to provide your own getters
10682
/// to see whether anything was captured.
10783
struct CaptureTracker {
108-
/// Action returned from captures().
109-
enum Action {
110-
/// Stop the traversal.
111-
Stop,
112-
/// Continue traversal, and also follow the return value of the user if
113-
/// it has additional capture components (that is, if it has capture
114-
/// components in Ret that are not part of Other).
115-
Continue,
116-
/// Continue traversal, but do not follow the return value of the user,
117-
/// even if it has additional capture components. Should only be used if
118-
/// captures() has already taken the potential return captures into
119-
/// account.
120-
ContinueIgnoringReturn,
121-
};
122-
12384
virtual ~CaptureTracker();
12485

12586
/// tooManyUses - The depth of traversal has breached a limit. There may be
@@ -133,31 +94,32 @@ namespace llvm {
13394
/// U->getUser() is always an Instruction.
13495
virtual bool shouldExplore(const Use *U);
13596

136-
/// Use U directly captures CI.UseCC and additionally CI.ResultCC
137-
/// through the return value of the user of U.
138-
///
139-
/// Return one of Stop, Continue or ContinueIgnoringReturn to control
140-
/// further traversal.
141-
virtual Action captured(const Use *U, UseCaptureInfo CI) = 0;
97+
/// captured - Information about the pointer was captured by the user of
98+
/// use U. Return true to stop the traversal or false to continue looking
99+
/// for more capturing instructions.
100+
virtual bool captured(const Use *U) = 0;
142101

143102
/// isDereferenceableOrNull - Overload to allow clients with additional
144103
/// knowledge about pointer dereferenceability to provide it and thereby
145104
/// avoid conservative responses when a pointer is compared to null.
146105
virtual bool isDereferenceableOrNull(Value *O, const DataLayout &DL);
147106
};
148107

108+
/// Types of use capture kinds, see \p DetermineUseCaptureKind.
109+
enum class UseCaptureKind {
110+
NO_CAPTURE,
111+
MAY_CAPTURE,
112+
PASSTHROUGH,
113+
};
114+
149115
/// Determine what kind of capture behaviour \p U may exhibit.
150116
///
151-
/// The returned UseCaptureInfo contains the components captured directly
152-
/// by the use (UseCC) and the components captured through the return value
153-
/// of the user (ResultCC).
154-
///
155-
/// \p Base is the starting value of the capture analysis, which is
156-
/// relevant for address_is_null captures.
117+
/// A use can be no-capture, a use can potentially capture, or a use can be
118+
/// passthrough such that the uses of the user or \p U should be inspected.
157119
/// The \p IsDereferenceableOrNull callback is used to rule out capturing for
158120
/// certain comparisons.
159-
UseCaptureInfo
160-
DetermineUseCaptureKind(const Use &U, const Value *Base,
121+
UseCaptureKind
122+
DetermineUseCaptureKind(const Use &U,
161123
llvm::function_ref<bool(Value *, const DataLayout &)>
162124
IsDereferenceableOrNull);
163125

llvm/include/llvm/Support/ModRef.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,6 @@ inline bool capturesFullProvenance(CaptureComponents CC) {
326326
return (CC & CaptureComponents::Provenance) == CaptureComponents::Provenance;
327327
}
328328

329-
inline bool capturesAll(CaptureComponents CC) {
330-
return CC == CaptureComponents::All;
331-
}
332-
333329
raw_ostream &operator<<(raw_ostream &OS, CaptureComponents CC);
334330

335331
/// Represents which components of the pointer may be captured in which
@@ -354,15 +350,6 @@ class CaptureInfo {
354350
/// Create CaptureInfo that may capture all components of the pointer.
355351
static CaptureInfo all() { return CaptureInfo(CaptureComponents::All); }
356352

357-
/// Create CaptureInfo that may only capture via the return value.
358-
static CaptureInfo
359-
retOnly(CaptureComponents RetComponents = CaptureComponents::All) {
360-
return CaptureInfo(CaptureComponents::None, RetComponents);
361-
}
362-
363-
/// Whether the pointer is only captured via the return value.
364-
bool isRetOnly() const { return capturesNothing(OtherComponents); }
365-
366353
/// Get components potentially captured by the return value.
367354
CaptureComponents getRetComponents() const { return RetComponents; }
368355

0 commit comments

Comments
 (0)