condy updated this revision to Diff 345767.
condy added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix some tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102592/new/

https://reviews.llvm.org/D102592

Files:
  clang/test/CodeGen/asan-globals-alias.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2372,6 +2372,18 @@
     return false;
   }
 
+  // Create a global zero-sized array precedence before GlobalsToChange[0] so
+  // that the underflow of the it could be observable.
+  ArrayType *ZeroSizedArrayTy = ArrayType::get(IRB.getInt8Ty(), 0);
+  GlobalVariable *UnderflowObserverGV = new GlobalVariable(
+      M, ZeroSizedArrayTy, /*isConstant*/ false, 
GlobalVariable::PrivateLinkage,
+      ConstantArray::get(ZeroSizedArrayTy, {}), kAsanGenPrefix,
+      GlobalsToChange[0]);
+  GlobalsToChange.insert(GlobalsToChange.begin(), UnderflowObserverGV);
+
+  // Update size as we insert a dummy one.
+  n = GlobalsToChange.size();
+
   auto &DL = M.getDataLayout();
 
   // A global is described by a structure
Index: clang/test/CodeGen/asan-globals-odr.cpp
===================================================================
--- clang/test/CodeGen/asan-globals-odr.cpp
+++ clang/test/CodeGen/asan-globals-odr.cpp
@@ -24,7 +24,7 @@
 // GLOB_ALIAS_INDICATOR: @0 = internal global {{.*}} @1 to i64), {{.*}}, i64 
ptrtoint (i8* [[ODR]] to i64) }]
 
 // ALIAS0-NOT: private alias
-// ALIAS1: @1 = private alias {{.*}} [[VAR]]
+// ALIAS1: @2 = private alias {{.*}} [[VAR]]
 
-// CHECK: call void @__asan_register_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
-// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
+// CHECK: call void @__asan_register_globals(i64 ptrtoint ([2 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
+// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([2 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
Index: clang/test/CodeGen/asan-globals-alias.cpp
===================================================================
--- clang/test/CodeGen/asan-globals-alias.cpp
+++ clang/test/CodeGen/asan-globals-alias.cpp
@@ -36,8 +36,8 @@
 // CHECK: @__mod_joydev_ids_device_table ={{.*}} alias
 
 // CHECK-LABEL: define internal void @asan.module_ctor
-// ASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 4)
-// KASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 1)
+// ASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 5)
+// KASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 2)
 // CHECK-NEXT: ret void
 
 // CHECK-LABEL: define internal void @asan.module_dtor


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2372,6 +2372,18 @@
     return false;
   }
 
+  // Create a global zero-sized array precedence before GlobalsToChange[0] so
+  // that the underflow of the it could be observable.
+  ArrayType *ZeroSizedArrayTy = ArrayType::get(IRB.getInt8Ty(), 0);
+  GlobalVariable *UnderflowObserverGV = new GlobalVariable(
+      M, ZeroSizedArrayTy, /*isConstant*/ false, GlobalVariable::PrivateLinkage,
+      ConstantArray::get(ZeroSizedArrayTy, {}), kAsanGenPrefix,
+      GlobalsToChange[0]);
+  GlobalsToChange.insert(GlobalsToChange.begin(), UnderflowObserverGV);
+
+  // Update size as we insert a dummy one.
+  n = GlobalsToChange.size();
+
   auto &DL = M.getDataLayout();
 
   // A global is described by a structure
Index: clang/test/CodeGen/asan-globals-odr.cpp
===================================================================
--- clang/test/CodeGen/asan-globals-odr.cpp
+++ clang/test/CodeGen/asan-globals-odr.cpp
@@ -24,7 +24,7 @@
 // GLOB_ALIAS_INDICATOR: @0 = internal global {{.*}} @1 to i64), {{.*}}, i64 ptrtoint (i8* [[ODR]] to i64) }]
 
 // ALIAS0-NOT: private alias
-// ALIAS1: @1 = private alias {{.*}} [[VAR]]
+// ALIAS1: @2 = private alias {{.*}} [[VAR]]
 
-// CHECK: call void @__asan_register_globals(i64 ptrtoint ([1 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
-// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([1 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
+// CHECK: call void @__asan_register_globals(i64 ptrtoint ([2 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
+// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([2 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
Index: clang/test/CodeGen/asan-globals-alias.cpp
===================================================================
--- clang/test/CodeGen/asan-globals-alias.cpp
+++ clang/test/CodeGen/asan-globals-alias.cpp
@@ -36,8 +36,8 @@
 // CHECK: @__mod_joydev_ids_device_table ={{.*}} alias
 
 // CHECK-LABEL: define internal void @asan.module_ctor
-// ASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 4)
-// KASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 1)
+// ASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 5)
+// KASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 2)
 // CHECK-NEXT: ret void
 
 // CHECK-LABEL: define internal void @asan.module_dtor
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to