-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tsan: fix XMM register corruption in hacky call
The compiler does not recognize HACKY_CALL as a call (we intentionally hide it from the compiler so that it can compile non-leaf functions as leaf functions). To compensate for that hacky call thunk saves and restores all caller-saved registers. However, it saves only general-purposes registers and does not save XMM registers. This is a latent bug that was masked up until a recent "NFC" commit d736002 ("tsan: move memory access functions to a separate file"), which allowed more inlining and exposed the 10-year bug. Save and restore caller-saved XMM registers (all) as well. Currently the bug manifests as e.g. frexp interceptor messes the return value and the added test fails with: i=8177 y=0.000000 exp=4 Reviewed By: melver Differential Revision: https://reviews.llvm.org/D113742
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s | ||
|
||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int main() { | ||
for (int i = 0; i < 10000; i++) { | ||
volatile double x = 10; | ||
int exp = 0; | ||
double y = frexp(x, &exp); | ||
if (y != 0.625 || exp != 4) { | ||
printf("i=%d y=%lf exp=%d\n", i, y, exp); | ||
exit(1); | ||
} | ||
} | ||
fprintf(stderr, "DONE\n"); | ||
// CHECK: DONE | ||
return 0; | ||
} |