[cfe-commits] r155430 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenTBAA.cpp lib/CodeGen/CodeGenTBAA.h test/CodeGen/tbaa-for-vptr.cpp

Kostya Serebryany kcc at google.com
Mon Apr 23 23:57:01 PDT 2012


Author: kcc
Date: Tue Apr 24 01:57:01 2012
New Revision: 155430

URL: http://llvm.org/viewvc/llvm-project?rev=155430&view=rev
Log:
enable TBAA when -fthread-sanitizer is given, even with -O0 or  -relaxed-aliasing 

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
    cfe/trunk/lib/CodeGen/CodeGenTBAA.h
    cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=155430&r1=155429&r2=155430&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 24 01:57:01 2012
@@ -102,9 +102,10 @@
   if (LangOpts.CUDA)
     createCUDARuntime();
 
-  // Enable TBAA unless it's suppressed.
-  if (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)
-    TBAA = new CodeGenTBAA(Context, VMContext, getLangOpts(),
+  // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0.
+  if (LangOpts.ThreadSanitizer ||
+      (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0))
+    TBAA = new CodeGenTBAA(Context, VMContext, CodeGenOpts, getLangOpts(),
                            ABI.getMangleContext());
 
   // If debug info or coverage generation is enabled, create the CGDebugInfo

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=155430&r1=155429&r2=155430&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Tue Apr 24 01:57:01 2012
@@ -18,6 +18,7 @@
 #include "CodeGenTBAA.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Mangle.h"
+#include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Metadata.h"
 #include "llvm/Constants.h"
@@ -26,8 +27,10 @@
 using namespace CodeGen;
 
 CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext& VMContext,
+                         const CodeGenOptions &CGO,
                          const LangOptions &Features, MangleContext &MContext)
-  : Context(Ctx), VMContext(VMContext), Features(Features), MContext(MContext),
+  : Context(Ctx), VMContext(VMContext), CodeGenOpts(CGO),
+    Features(Features), MContext(MContext),
     MDHelper(VMContext), Root(0), Char(0) {
 }
 
@@ -74,6 +77,10 @@
 
 llvm::MDNode *
 CodeGenTBAA::getTBAAInfo(QualType QTy) {
+  // At -O0 TBAA is not emitted for regular types.
+  if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
+    return NULL;
+
   // If the type has the may_alias attribute (even on a typedef), it is
   // effectively in the general char alias class.
   if (TypeHasMayAlias(QTy))

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.h?rev=155430&r1=155429&r2=155430&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.h Tue Apr 24 01:57:01 2012
@@ -26,6 +26,7 @@
 
 namespace clang {
   class ASTContext;
+  class CodeGenOptions;
   class LangOptions;
   class MangleContext;
   class QualType;
@@ -39,6 +40,7 @@
 class CodeGenTBAA {
   ASTContext &Context;
   llvm::LLVMContext& VMContext;
+  const CodeGenOptions &CodeGenOpts;
   const LangOptions &Features;
   MangleContext &MContext;
 
@@ -61,6 +63,7 @@
 
 public:
   CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext,
+              const CodeGenOptions &CGO,
               const LangOptions &Features,
               MangleContext &MContext);
   ~CodeGenTBAA();

Modified: cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp?rev=155430&r1=155429&r2=155430&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp (original)
+++ cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp Tue Apr 24 01:57:01 2012
@@ -1,5 +1,13 @@
+// RUN: %clang_cc1 -emit-llvm -o - -O0 -fthread-sanitizer %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -O1 %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - -O1  -relaxed-aliasing -fthread-sanitizer %s | FileCheck %s
+//
+// RUN: %clang_cc1 -emit-llvm -o - -O0 %s | FileCheck %s --check-prefix=NOTBAA
+// RUN: %clang_cc1 -emit-llvm -o - -O2  -relaxed-aliasing %s | FileCheck %s --check-prefix=NOTBAA
+//
 // Check that we generate TBAA for vtable pointer loads and stores.
+// When -fthread-sanitizer is used TBAA should be generated at all opt levels
+// even if -relaxed-aliasing is present.
 struct A {
   virtual int foo() const ;
   virtual ~A();
@@ -15,5 +23,5 @@
 
 // CHECK: %{{.*}} = load {{.*}} !tbaa !0
 // CHECK: store {{.*}} !tbaa !0
-// CHECK: !0 = metadata !{metadata !"vtable pointer", metadata !1}
-// CHECK: !1 = metadata !{metadata !"Simple C/C++ TBAA"}
+// CHECK: = metadata !{metadata !"vtable pointer", metadata !{{.*}}}
+// NOTBAA-NOT: = metadata !{metadata !"Simple C/C++ TBAA"}





More information about the cfe-commits mailing list