Page MenuHomePhabricator

[Sanitizers] Add a flag -f[no-]sanitize-merge-traps
Needs ReviewPublic

Authored by rnk on Thu, Apr 8, 3:56 PM.

Details

Summary

Without this flag, enabling optimizations causes clang to emit a single
ubsantrap for every check failure of a particular kind. Adding this flag
allows the user to control this behavior separately, so they can choose
to have increased code size in exchange for more debuggable code.

A Chrome developer requested this feature here:
https://crbug.com/1185451

I made this change in such a way that it doesn't litter the cc1 line
with redundant flags: if the user does not pass the positive or negative
version if this flag, it is not forwarded to the cc1 invocation.

Diff Detail

Unit TestsFailed

TimeTest
30 msx64 debian > Clang.CodeGen::cfi-nomerge.c
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/llvm-project/build/lib/clang/13.0.0/include -nostdsysteminc -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -emit-llvm -o - /mnt/disks/ssd0/agent/llvm-project/clang/test/CodeGen/cfi-nomerge.c -fsanitize-merge-traps | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck --check-prefix=MERGE /mnt/disks/ssd0/agent/llvm-project/clang/test/CodeGen/cfi-nomerge.c
50 msx64 debian > Clang.CodeGen::trapv-nomerge.c
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/llvm-project/build/lib/clang/13.0.0/include -nostdsysteminc -O2 -triple x86_64-apple-darwin10 -ftrapv -fno-sanitize-merge-traps /mnt/disks/ssd0/agent/llvm-project/clang/test/CodeGen/trapv-nomerge.c -emit-llvm -o - | /mnt/disks/ssd0/agent/llvm-project/build/bin/FileCheck /mnt/disks/ssd0/agent/llvm-project/clang/test/CodeGen/trapv-nomerge.c --check-prefix=NOMERGE
70 msx64 windows > Clang.CodeGen::cfi-nomerge.c
Script: -- : 'RUN: at line 1'; c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\13.0.0\include -nostdsysteminc -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -emit-llvm -o - C:\ws\w32-1\llvm-project\premerge-checks\clang\test\CodeGen\cfi-nomerge.c -fsanitize-merge-traps | c:\ws\w32-1\llvm-project\premerge-checks\build\bin\filecheck.exe --check-prefix=MERGE C:\ws\w32-1\llvm-project\premerge-checks\clang\test\CodeGen\cfi-nomerge.c
80 msx64 windows > Clang.CodeGen::trapv-nomerge.c
Script: -- : 'RUN: at line 1'; c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\13.0.0\include -nostdsysteminc -O2 -triple x86_64-apple-darwin10 -ftrapv -fno-sanitize-merge-traps C:\ws\w32-1\llvm-project\premerge-checks\clang\test\CodeGen\trapv-nomerge.c -emit-llvm -o - | c:\ws\w32-1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w32-1\llvm-project\premerge-checks\clang\test\CodeGen\trapv-nomerge.c --check-prefix=NOMERGE

Event Timeline

rnk created this revision.Thu, Apr 8, 3:56 PM
rnk requested review of this revision.Thu, Apr 8, 3:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptThu, Apr 8, 3:56 PM

The CodeGen tests you added are failing pre-merge checks. This is most likely because we recently (D97462) started verifying that all all CC1 command line options can be serialized from a CompilerInvocation instance. To reproduce this locally, you'd need to build with assertions or manually set -DCLANG_ROUND_TRIP_CC1_ARGS=ON when building with CMake.

The solution would be to add complementary code that generates "-f[no-]sanitize-merge-traps" from CodeGenOptions::SanitizeMergeTraps in CompilerInvocation::GenerateCodeGenArgs.

More info is here https://clang.llvm.org/docs/InternalsManual.html#compiler-invocation and in the following sections.