1; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-inline-8bit-counters=1 -sanitizer-coverage-pc-table=1 -S -enable-new-pm=0 | FileCheck %s 2; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-inline-8bit-counters=1 -sanitizer-coverage-pc-table=1 -S | FileCheck %s 3 4; Make sure we use the right comdat groups for COFF to avoid relocations 5; against discarded sections. Internal linkage functions are also different from 6; ELF. We don't add a module unique identifier. 7 8; Test based on this source: 9; int baz(int); 10; static int __attribute__((noinline)) bar(int x) { 11; if (x) 12; return baz(x); 13; return 0; 14; } 15; int foo(int x) { 16; if (baz(0)) 17; x = bar(x); 18; return x; 19; } 20 21; Both new comdats should no duplicates on COFF. 22 23; CHECK: $foo = comdat noduplicates 24; CHECK: $bar = comdat noduplicates 25 26; Tables for 'foo' should be in the 'foo' comdat. 27 28; CHECK: @__sancov_gen_{{.*}} = private global [1 x i8] zeroinitializer, section ".SCOV$CM", comdat($foo), align 1 29 30; CHECK: @__sancov_gen_{{.*}} = private constant [2 x i64*] 31; CHECK-SAME: [i64* bitcast (i32 (i32)* @foo to i64*), i64* inttoptr (i64 1 to i64*)], 32; CHECK-SAME: section ".SCOVP$M", comdat($foo), align 8 33 34; Tables for 'bar' should be in the 'bar' comdat. 35 36; CHECK: @__sancov_gen_{{.*}} = private global [1 x i8] zeroinitializer, section ".SCOV$CM", comdat($bar), align 1 37 38; CHECK: @__sancov_gen_{{.*}} = private constant [2 x i64*] 39; CHECK-SAME: [i64* bitcast (i32 (i32)* @bar to i64*), i64* inttoptr (i64 1 to i64*)], 40; CHECK-SAME: section ".SCOVP$M", comdat($bar), align 8 41 42; 'foo' and 'bar' should be in their new comdat groups. 43 44; CHECK: define dso_local i32 @foo(i32 %x){{.*}} comdat { 45; CHECK: define internal fastcc i32 @bar(i32 %x){{.*}} comdat { 46 47target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" 48target triple = "x86_64-pc-windows-msvc19.14.26433" 49 50; Function Attrs: nounwind uwtable 51define dso_local i32 @foo(i32 %x) local_unnamed_addr #0 { 52entry: 53 %call = tail call i32 @baz(i32 0) #3 54 %tobool = icmp eq i32 %call, 0 55 br i1 %tobool, label %if.end, label %if.then 56 57if.then: ; preds = %entry 58 %call1 = tail call fastcc i32 @bar(i32 %x) 59 br label %if.end 60 61if.end: ; preds = %entry, %if.then 62 %x.addr.0 = phi i32 [ %call1, %if.then ], [ %x, %entry ] 63 ret i32 %x.addr.0 64} 65 66declare dso_local i32 @baz(i32) local_unnamed_addr #1 67 68; Function Attrs: noinline nounwind uwtable 69define internal fastcc i32 @bar(i32 %x) unnamed_addr #2 { 70entry: 71 %tobool = icmp eq i32 %x, 0 72 br i1 %tobool, label %return, label %if.then 73 74if.then: ; preds = %entry 75 %call = tail call i32 @baz(i32 %x) #3 76 br label %return 77 78return: ; preds = %entry, %if.then 79 %retval.0 = phi i32 [ %call, %if.then ], [ 0, %entry ] 80 ret i32 %retval.0 81} 82 83attributes #0 = { nounwind uwtable } 84attributes #1 = { "asdf" } 85attributes #2 = { noinline nounwind uwtable } 86attributes #3 = { nounwind } 87