Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1808,6 +1808,8 @@ if (GlobalsMD.get(G).IsBlacklisted) return false; if (!Ty->isSized()) return false; if (!G->hasInitializer()) return false; + // Only instrument globals of default address spaces + if (G->getAddressSpace()) return false; if (GlobalWasGeneratedByCompiler(G)) return false; // Our own globals. // Two problems with thread-locals: // - The address of the main thread's copy can't be computed at link-time. Index: test/Instrumentation/AddressSanitizer/global_addrspace.ll =================================================================== --- /dev/null +++ test/Instrumentation/AddressSanitizer/global_addrspace.ll @@ -0,0 +1,41 @@ +; Only verify that asan don't crash on global variables of different +; address space. The global variable should be unmodified by asan. + +; RUN: opt < %s -asan -asan-module -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@a = internal addrspace(42) global [1 x i32] zeroinitializer, align 4 + +; CHECK: @a = internal addrspace(42) global [1 x i32] zeroinitializer, align 4 + +define void @b(i32 %c) { +entry: + %conv = sext i32 %c to i64 + %0 = inttoptr i64 %conv to i32 addrspace(42)* + %cmp = icmp ugt i32 addrspace(42)* %0, getelementptr inbounds ([1 x i32], [1 x i32] addrspace(42)* @a, i64 0, i64 0) + br i1 %cmp, label %if.then, label %if.end + +if.then: + %call = tail call i32 (...) @e() + br label %if.end + +if.end: + ret void +} + +declare i32 @e(...) + +!llvm.dbg.cu = !{!0} +!llvm.asan.globals = !{!3} +!llvm.module.flags = !{!6, !7, !8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "foo.c", directory: "/") +!2 = !{} +!3 = !{[1 x i32] addrspace(42)* @a, !4, !"a", i1 false, i1 false} +!4 = !{!"foo.c", i32 1, i32 17} +!6 = !{i32 2, !"Dwarf Version", i32 4} +!7 = !{i32 2, !"Debug Info Version", i32 3} +!8 = !{i32 1, !"wchar_size", i32 4}