[compiler-rt] r288064 - [sanitizers] Get the proper printf/scanf version when long double transition is involved.
Marcin Koscielnicki via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 28 13:15:20 PST 2016
Author: koriakin
Date: Mon Nov 28 15:15:19 2016
New Revision: 288064
URL: http://llvm.org/viewvc/llvm-project?rev=288064&view=rev
Log:
[sanitizers] Get the proper printf/scanf version when long double transition is involved.
See D19555 for rationale. As it turns out, this treatment is also necessary
for scanf/printf.
Differential Revision: https://reviews.llvm.org/D27118
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/printf-ldbl.c
compiler-rt/trunk/test/sanitizer_common/TestCases/scanf-ldbl.c
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=288064&r1=288063&r2=288064&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Nov 28 15:15:19 2016
@@ -1239,12 +1239,12 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_sscanf,
#if SANITIZER_INTERCEPT_SCANF
#define INIT_SCANF \
- COMMON_INTERCEPT_FUNCTION(scanf); \
- COMMON_INTERCEPT_FUNCTION(sscanf); \
- COMMON_INTERCEPT_FUNCTION(fscanf); \
- COMMON_INTERCEPT_FUNCTION(vscanf); \
- COMMON_INTERCEPT_FUNCTION(vsscanf); \
- COMMON_INTERCEPT_FUNCTION(vfscanf);
+ COMMON_INTERCEPT_FUNCTION_LDBL(scanf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(sscanf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(fscanf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vscanf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vsscanf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vfscanf);
#else
#define INIT_SCANF
#endif
@@ -1417,16 +1417,16 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_snprint
#if SANITIZER_INTERCEPT_PRINTF
#define INIT_PRINTF \
- COMMON_INTERCEPT_FUNCTION(printf); \
- COMMON_INTERCEPT_FUNCTION(sprintf); \
- COMMON_INTERCEPT_FUNCTION(snprintf); \
- COMMON_INTERCEPT_FUNCTION(asprintf); \
- COMMON_INTERCEPT_FUNCTION(fprintf); \
- COMMON_INTERCEPT_FUNCTION(vprintf); \
- COMMON_INTERCEPT_FUNCTION(vsprintf); \
- COMMON_INTERCEPT_FUNCTION(vsnprintf); \
- COMMON_INTERCEPT_FUNCTION(vasprintf); \
- COMMON_INTERCEPT_FUNCTION(vfprintf);
+ COMMON_INTERCEPT_FUNCTION_LDBL(printf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(sprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(snprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(asprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(fprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vasprintf); \
+ COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
#else
#define INIT_PRINTF
#endif
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/printf-ldbl.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/printf-ldbl.c?rev=288064&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/printf-ldbl.c (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/printf-ldbl.c Mon Nov 28 15:15:19 2016
@@ -0,0 +1,13 @@
+// RUN: %clang %s -o %t && %run %t 2>&1
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ char buf[20];
+ long double ld = 4.0;
+ snprintf(buf, sizeof buf, "%Lf %d", ld, 123);
+ assert(!strcmp(buf, "4.000000 123"));
+ return 0;
+}
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/scanf-ldbl.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/scanf-ldbl.c?rev=288064&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/scanf-ldbl.c (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/scanf-ldbl.c Mon Nov 28 15:15:19 2016
@@ -0,0 +1,13 @@
+// RUN: %clang %s -o %t && %run %t 2>&1
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ long double ld;
+ memset(&ld, 255, sizeof ld);
+ sscanf("4.0", "%Lf", &ld);
+ assert(ld == 4.0);
+ return 0;
+}
More information about the llvm-commits
mailing list