[clang] [TBAA] Add bail-out to skip tbaa generation to getTBAAStructInfo. (PR #84386)

Florian Hahn via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 7 13:49:14 PST 2024


https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/84386

Without this bail out, we may generate fields with null nodes as tags are generated by using getTypeInfo which has the same bail out.

>From 36144a7b2a84b10711904c1a568bf02554f83296 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Thu, 7 Mar 2024 21:45:49 +0000
Subject: [PATCH] [TBAA] Add bail-out to skip tbaa generation to
 getTBAAStructInfo.

Without this bail out, we may generate fields with null nodes as tags
are generated by using getTypeInfo which has the same bail out.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp                             | 3 +++
 clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8a081612193978..1f07205a5af225 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -343,6 +343,9 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
 
 llvm::MDNode *
 CodeGenTBAA::getTBAAStructInfo(QualType QTy) {
+  if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
+    return nullptr;
+
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
 
   if (llvm::MDNode *N = StructMetadataCache[Ty])
diff --git a/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp b/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp
index 931ff2476cd1bb..ce613b9d6b23f8 100644
--- a/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp
+++ b/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp
@@ -5,9 +5,7 @@
 // RUN:     FileCheck %s
 //
 // Check that we do not create tbaa for instructions generated for copies.
-// FIXME: !tbaa.struct is generated with null node as tag.
 
-// CHECK: !tbaa.struct
 // CHECK-NOT: !tbaa
 
 struct A {



More information about the cfe-commits mailing list