Skip to content

Commit bee2403

Browse files
committed
Revert "[TBAA] Emit distinct TBAA tags for pointers with different depths,types. (#76612)"
This reverts commit 038c48c. This is causing test failures in some configurations, reverted while I investigate. Failures include http://lab.llvm.org/buildbot/#/builders/11/builds/1623 http://lab.llvm.org/buildbot/#/builders/108/builds/1172
1 parent 99685a5 commit bee2403

File tree

9 files changed

+472
-565
lines changed

9 files changed

+472
-565
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,6 @@ Non-comprehensive list of changes in this release
425425
- Added support for ``TypeLoc::dump()`` for easier debugging, and improved
426426
textual and JSON dumping for various ``TypeLoc``-related nodes.
427427

428-
- Clang can now emit distinct type-based alias analysis tags for incompatible
429-
pointers, enabling more powerful alias analysis when accessing pointer types.
430-
The new behavior can be enabled using ``-fpointer-tbaa``.
431-
432428
New Compiler Flags
433429
------------------
434430
- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
@@ -471,9 +467,6 @@ New Compiler Flags
471467
- For the ARM target, added ``-Warm-interrupt-vfp-clobber`` that will emit a
472468
diagnostic when an interrupt handler is declared and VFP is enabled.
473469

474-
- ``-fpointer-tbaa`` enables emission of distinct type-based alias
475-
analysis tags for incompatible pointers.
476-
477470
Deprecated Compiler Flags
478471
-------------------------
479472

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, SRCK_Defa
233233

234234
CODEGENOPT(RelaxAll , 1, 0) ///< Relax all machine code instructions.
235235
CODEGENOPT(RelaxedAliasing , 1, 0) ///< Set when -fno-strict-aliasing is enabled.
236-
CODEGENOPT(PointerTBAA, 1, 0) ///< Whether or not to use distinct TBAA tags for pointers.
237236
CODEGENOPT(StructPathTBAA , 1, 0) ///< Whether or not to use struct-path TBAA.
238237
CODEGENOPT(NewStructPathTBAA , 1, 0) ///< Whether or not to use enhanced struct-path TBAA.
239238
CODEGENOPT(SaveTempLabels , 1, 0) ///< Save temporary labels.

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,7 +3379,6 @@ def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group<f_Group>;
33793379
def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group<f_Group>;
33803380
def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
33813381
def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>;
3382-
def fno_pointer_tbaa : Flag<["-"], "fno-pointer-tbaa">, Group<f_Group>;
33833382
def fno_temp_file : Flag<["-"], "fno-temp-file">, Group<f_Group>,
33843383
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, HelpText<
33853384
"Directly create compilation output files. This may lead to incorrect incremental builds if the compiler crashes">,
@@ -3884,7 +3883,6 @@ defm strict_vtable_pointers : BoolFOption<"strict-vtable-pointers",
38843883
" overwriting polymorphic C++ objects">,
38853884
NegFlag<SetFalse>>;
38863885
def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group<f_Group>;
3887-
def fpointer_tbaa : Flag<["-"], "fpointer-tbaa">, Group<f_Group>;
38883886
def fdriver_only : Flag<["-"], "fdriver-only">, Flags<[NoXarchOption]>,
38893887
Visibility<[ClangOption, CLOption, DXCOption]>,
38903888
Group<Action_Group>, HelpText<"Only run the driver.">;
@@ -7148,9 +7146,6 @@ def fuse_register_sized_bitfield_access: Flag<["-"], "fuse-register-sized-bitfie
71487146
def relaxed_aliasing : Flag<["-"], "relaxed-aliasing">,
71497147
HelpText<"Turn off Type Based Alias Analysis">,
71507148
MarshallingInfoFlag<CodeGenOpts<"RelaxedAliasing">>;
7151-
def pointer_tbaa: Flag<["-"], "pointer-tbaa">,
7152-
HelpText<"Turn on Type Based Alias Analysis for pointer accesses">,
7153-
MarshallingInfoFlag<CodeGenOpts<"PointerTBAA">>;
71547149
def no_struct_path_tbaa : Flag<["-"], "no-struct-path-tbaa">,
71557150
HelpText<"Turn off struct-path aware Type Based Alias Analysis">,
71567151
MarshallingInfoNegativeFlag<CodeGenOpts<"StructPathTBAA">>;

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -185,56 +185,10 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
185185
return getChar();
186186

187187
// Handle pointers and references.
188-
//
189-
// C has a very strict rule for pointer aliasing. C23 6.7.6.1p2:
190-
// For two pointer types to be compatible, both shall be identically
191-
// qualified and both shall be pointers to compatible types.
192-
//
193-
// This rule is impractically strict; we want to at least ignore CVR
194-
// qualifiers. Distinguishing by CVR qualifiers would make it UB to
195-
// e.g. cast a `char **` to `const char * const *` and dereference it,
196-
// which is too common and useful to invalidate. C++'s similar types
197-
// rule permits qualifier differences in these nested positions; in fact,
198-
// C++ even allows that cast as an implicit conversion.
199-
//
200-
// Other qualifiers could theoretically be distinguished, especially if
201-
// they involve a significant representation difference. We don't
202-
// currently do so, however.
203-
//
204-
// Computing the pointee type string recursively is implicitly more
205-
// forgiving than the standards require. Effectively, we are turning
206-
// the question "are these types compatible/similar" into "are
207-
// accesses to these types allowed to alias". In both C and C++,
208-
// the latter question has special carve-outs for signedness
209-
// mismatches that only apply at the top level. As a result, we are
210-
// allowing e.g. `int *` l-values to access `unsigned *` objects.
211-
if (Ty->isPointerType() || Ty->isReferenceType()) {
212-
llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), Size);
213-
if (!CodeGenOpts.PointerTBAA)
214-
return AnyPtr;
215-
// Compute the depth of the pointer and generate a tag of the form "p<depth>
216-
// <base type tag>".
217-
unsigned PtrDepth = 0;
218-
do {
219-
PtrDepth++;
220-
Ty = Ty->getPointeeType().getTypePtr();
221-
} while (Ty->isPointerType());
222-
// TODO: Implement C++'s type "similarity" and consider dis-"similar"
223-
// pointers distinct for non-builtin types.
224-
if (isa<BuiltinType>(Ty)) {
225-
llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty);
226-
StringRef Name =
227-
cast<llvm::MDString>(
228-
ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0))
229-
->getString();
230-
SmallString<256> OutName("p");
231-
OutName += std::to_string(PtrDepth);
232-
OutName += " ";
233-
OutName += Name;
234-
return createScalarTypeNode(OutName, AnyPtr, Size);
235-
}
236-
return AnyPtr;
237-
}
188+
// TODO: Implement C++'s type "similarity" and consider dis-"similar"
189+
// pointers distinct.
190+
if (Ty->isPointerType() || Ty->isReferenceType())
191+
return createScalarTypeNode("any pointer", getChar(), Size);
238192

239193
// Accesses to arrays are accesses to objects of their element types.
240194
if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,9 +5721,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57215721
if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
57225722
options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
57235723
CmdArgs.push_back("-relaxed-aliasing");
5724-
if (Args.hasFlag(options::OPT_fpointer_tbaa, options::OPT_fno_pointer_tbaa,
5725-
false))
5726-
CmdArgs.push_back("-pointer-tbaa");
57275724
if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
57285725
options::OPT_fno_struct_path_tbaa, true))
57295726
CmdArgs.push_back("-no-struct-path-tbaa");

clang/test/CodeGen/sanitize-metadata-nosanitize.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//.
1313
// CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none)
1414
// CHECK-LABEL: define dso_local void @escape
15-
// CHECK-SAME: (ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !pcsections [[META2:![0-9]+]] {
15+
// CHECK-SAME: (ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !pcsections !2 {
1616
// CHECK-NEXT: entry:
1717
// CHECK-NEXT: ret void
1818
//
@@ -23,13 +23,13 @@ __attribute__((noinline, not_tail_called)) void escape(const volatile void *p) {
2323

2424
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
2525
// CHECK-LABEL: define dso_local i32 @normal_function
26-
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !pcsections [[META4:![0-9]+]] {
26+
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !pcsections !4 {
2727
// CHECK-NEXT: entry:
2828
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
2929
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6:![0-9]+]]
30-
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections [[META11:![0-9]+]]
30+
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10
3131
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
32-
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA12:![0-9]+]]
32+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11:![0-9]+]]
3333
// CHECK-NEXT: ret i32 [[TMP0]]
3434
//
3535
int normal_function(int *x, int *y) {
@@ -46,7 +46,7 @@ int normal_function(int *x, int *y) {
4646
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]]
4747
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4
4848
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
49-
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA12]]
49+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]]
5050
// CHECK-NEXT: ret i32 [[TMP0]]
5151
//
5252
__attribute__((disable_sanitizer_instrumentation)) int test_disable_sanitize_instrumentation(int *x, int *y) {
@@ -57,13 +57,13 @@ __attribute__((disable_sanitizer_instrumentation)) int test_disable_sanitize_ins
5757

5858
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
5959
// CHECK-LABEL: define dso_local i32 @test_no_sanitize_thread
60-
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] !pcsections [[META14:![0-9]+]] {
60+
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] !pcsections !13 {
6161
// CHECK-NEXT: entry:
6262
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
6363
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]]
64-
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections [[META11]]
64+
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10
6565
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
66-
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA12]]
66+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]]
6767
// CHECK-NEXT: ret i32 [[TMP0]]
6868
//
6969
__attribute__((no_sanitize("thread"))) int test_no_sanitize_thread(int *x, int *y) {
@@ -74,13 +74,13 @@ __attribute__((no_sanitize("thread"))) int test_no_sanitize_thread(int *x, int *
7474

7575
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
7676
// CHECK-LABEL: define dso_local i32 @test_no_sanitize_all
77-
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3]] !pcsections [[META14]] {
77+
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3]] !pcsections !13 {
7878
// CHECK-NEXT: entry:
7979
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
8080
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]]
81-
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections [[META11]]
81+
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10
8282
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
83-
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA12]]
83+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]]
8484
// CHECK-NEXT: ret i32 [[TMP0]]
8585
//
8686
__attribute__((no_sanitize("all"))) int test_no_sanitize_all(int *x, int *y) {
@@ -89,9 +89,23 @@ __attribute__((no_sanitize("all"))) int test_no_sanitize_all(int *x, int *y) {
8989
return *y;
9090
}
9191
//.
92-
// CHECK: attributes #[[ATTR0]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
93-
// CHECK: attributes #[[ATTR1]] = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
94-
// CHECK: attributes #[[ATTR2]] = { disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
95-
// CHECK: attributes #[[ATTR3]] = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
96-
// CHECK: attributes #[[ATTR4:[0-9]+]] = { nounwind "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
92+
// CHECK: attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
93+
// CHECK: attributes #1 = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
94+
// CHECK: attributes #2 = { disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
95+
// CHECK: attributes #3 = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
96+
// CHECK: attributes #4 = { nounwind "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
97+
//.
98+
// CHECK: !2 = !{!"sanmd_covered2!C", !3}
99+
// CHECK: !3 = !{i64 0}
100+
// CHECK: !4 = !{!"sanmd_covered2!C", !5}
101+
// CHECK: !5 = !{i64 3}
102+
// CHECK: !6 = !{!7, !7, i64 0}
103+
// CHECK: !7 = !{!"any pointer", !8, i64 0}
104+
// CHECK: !8 = !{!"omnipotent char", !9, i64 0}
105+
// CHECK: !9 = !{!"Simple C/C++ TBAA"}
106+
// CHECK: !10 = !{!"sanmd_atomics2!C"}
107+
// CHECK: !11 = !{!12, !12, i64 0}
108+
// CHECK: !12 = !{!"int", !8, i64 0}
109+
// CHECK: !13 = !{!"sanmd_covered2!C", !14}
110+
// CHECK: !14 = !{i64 2}
97111
//.

0 commit comments

Comments
 (0)