[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 4 inline comments as done.
mgorny added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:49
+
+  fclose(fp);
+  return 0;

vitalybuka wrote:
> why does this close file only on success?
> I assume normal test behavior is return 0;
> So please replace all return N with  asserts so when it fail we will have 
> verbose output
> e.g
> ```
> assert(close(fd) != -1);
> 
> assert(ferror(fp));
> ```
> 
Will do. I've copied this from `fgets.cc`, `fputs_puts.cc` tests, and wrongly 
presumed it's expected coding style.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179679.
mgorny marked an inline comment as done.
mgorny added a comment.

Moved variable definitions, and added asserts.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136

Files:
  test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
  test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  fclose(fp);
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,40 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  fclose(fp);
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  fclose(fp);
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,40 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  fclose(fp);
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179681.
mgorny added a comment.

Implemented `fileno_unlocked` as requested.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56109/new/

https://reviews.llvm.org/D56109

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -42,16 +42,12 @@
 
 #if SANITIZER_NETBSD
 #define dirfd(dirp) (*(int *)(dirp))
-#define fileno_unlocked fileno
+#define fileno_unlocked(fp) \
+  (((__sanitizer_FILE*)fp)->_file == -1 ? -1 : \
+   (int)(unsigned short)(((__sanitizer_FILE*)fp)->_file))  // NOLINT
 
-#if _LP64
-#define __sF_size 152
-#else
-#define __sF_size 88
-#endif
-
-#define stdout ((char*)&__sF + (__sF_size * 1))
-#define stderr ((char*)&__sF + (__sF_size * 2))
+#define stdout ((__sanitizer_FILE*)&__sF[1])
+#define stderr ((__sanitizer_FILE*)&__sF[2])
 
 #define nanosleep __nanosleep50
 #define vfork __vfork14
@@ -96,8 +92,8 @@
 DECLARE_REAL_AND_INTERCEPTOR(void, free, void *ptr)
 extern "C" void *pthread_self();
 extern "C" void _exit(int status);
-extern "C" int fileno_unlocked(void *stream);
 #if !SANITIZER_NETBSD
+extern "C" int fileno_unlocked(void *stream);
 extern "C" int dirfd(void *dirp);
 #endif
 #if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_NETBSD
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -446,8 +446,36 @@
   uptr we_nbytes;
 };
 
-typedef char __sanitizer_FILE;
-#define SANITIZER_HAS_STRUCT_FILE 0
+struct __sanitizer_FILE {
+  unsigned char *_p;
+  int _r;
+  int _w;
+  unsigned short _flags;
+  short _file;
+  struct {
+unsigned char *_base;
+int _size;
+  } _bf;
+  int _lbfsize;
+  void *_cookie;
+  int (*_close)(void *ptr);
+  u64 (*_read)(void *, void *, uptr);
+  u64 (*_seek)(void *, u64, int);
+  uptr (*_write)(void *, const void *, uptr);
+  struct {
+unsigned char *_base;
+int _size;
+  } _ext;
+  unsigned char *_up;
+  int _ur;
+  unsigned char _ubuf[3];
+  unsigned char _nbuf[1];
+  int (*_flush)(void *ptr);
+  char _lb_unused[sizeof(uptr)];
+  int _blksize;
+  u64 _offset;
+};
+#define SANITIZER_HAS_STRUCT_FILE 1
 
 extern int shmctl_ipc_stat;
 
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
@@ -2224,6 +2224,29 @@
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
 
+COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
+CHECK_SIZE_AND_OFFSET(FILE, _p);
+CHECK_SIZE_AND_OFFSET(FILE, _r);
+CHECK_SIZE_AND_OFFSET(FILE, _w);
+CHECK_SIZE_AND_OFFSET(FILE, _flags);
+CHECK_SIZE_AND_OFFSET(FILE, _file);
+CHECK_SIZE_AND_OFFSET(FILE, _bf);
+CHECK_SIZE_AND_OFFSET(FILE, _lbfsize);
+CHECK_SIZE_AND_OFFSET(FILE, _cookie);
+CHECK_SIZE_AND_OFFSET(FILE, _close);
+CHECK_SIZE_AND_OFFSET(FILE, _read);
+CHECK_SIZE_AND_OFFSET(FILE, _seek);
+CHECK_SIZE_AND_OFFSET(FILE, _write);
+CHECK_SIZE_AND_OFFSET(FILE, _ext);
+CHECK_SIZE_AND_OFFSET(FILE, _up);
+CHECK_SIZE_AND_OFFSET(FILE, _ur);
+CHECK_SIZE_AND_OFFSET(FILE, _ubuf);
+CHECK_SIZE_AND_OFFSET(FILE, _nbuf);
+CHECK_SIZE_AND_OFFSET(FILE, _flush);
+CHECK_SIZE_AND_OFFSET(FILE, _lb_unused);
+CHECK_SIZE_AND_OFFSET(FILE, _blksize);
+CHECK_SIZE_AND_OFFSET(FILE, _offset);
+
 CHECK_TYPE_SIZE(tm);
 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
 CHECK_SIZE_AND_OFFSET(tm, tm_min);
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -5694,9 +5694,15 @@
 void unpoison_file(__sanitizer_FILE *fp) {
 #if SANITIZER_HAS_STRUCT_FILE
   COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp, sizeof(*fp));
+#if SANITIZER_NETBSD
+  if (fp->_bf._base && fp->_bf._size > 0)
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_bf._base,
+fp->_bf._size);
+#else
   if (fp->_IO_read_base && fp->_IO_read_base < fp->_IO_read_end)
 COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_IO_read_base,
 fp->_IO_read_end - fp->_IO_read_base);
+#endif
 #endif  // SANITIZER_HAS_STRUCT_FILE
 }
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski accepted this revision.
krytarowski added inline comments.
This revision is now accepted and ready to land.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:38
+
+  fclose(fp);
+  return 0;

`assert(!fclose(fp));`



Comment at: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc:17
+
+  fclose(fp);
+  return 0;

assert(!fclose(fp));


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:38
+
+  fclose(fp);
+  return 0;

krytarowski wrote:
> `assert(!fclose(fp));`
alternatively `!= EOF`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:38
+
+  fclose(fp);
+  return 0;

krytarowski wrote:
> krytarowski wrote:
> > `assert(!fclose(fp));`
> alternatively `!= EOF`
It will fail most likely, due to us closing the fd before. However, I'm not 
sure if we want to strictly rely on this error condition.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

(Do you have another idea how to reliably trigger `ferror`?)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54539: [CodeGen] Replace '@' characters in block descriptors' symbol names with '\1' on ELF targets.

2018-12-29 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 179676.
ahatanak added a comment.

Sorry for the delay. The updated patch replaces '@' with '\1' on all targets.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54539/new/

https://reviews.llvm.org/D54539

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGenObjC/block-desc-str.m
  test/CodeGenObjCXX/block-nested-in-lambda.mm


Index: test/CodeGenObjCXX/block-nested-in-lambda.mm
===
--- test/CodeGenObjCXX/block-nested-in-lambda.mm
+++ test/CodeGenObjCXX/block-nested-in-lambda.mm
@@ -35,7 +35,7 @@
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test0Ev(
 // CHECK-LABEL: define internal void 
@"_ZZN18CaptureByReference5test0EvENK3$_1clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* 
@"__block_descriptor_40_e5_v8@?0ls32l8" to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* 
@"__block_descriptor_40_e5_v8\01?0ls32l8" to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
 
 void test0() {
   id a = getObj();
@@ -48,7 +48,7 @@
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test1Ev(
 // CHECK-LABEL: define internal void 
@"_ZZN18CaptureByReference5test1EvENK3$_2clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8** }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8** }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i64 }* @"__block_descriptor_56_8_32s40s_e5_v8@?0l" to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 8
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i64 }* @"__block_descriptor_56_8_32s40s_e5_v8\01?0l" to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 8
 
 // CHECK-LABEL: define linkonce_odr hidden void @__copy_helper_block_8_32s40s(
 // CHECK-NOT: call void @llvm.objc.storeStrong(
Index: test/CodeGenObjC/block-desc-str.m
===
--- /dev/null
+++ test/CodeGenObjC/block-desc-str.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -emit-llvm 
-fobjc-runtime=gnustep-1.7 -fblocks -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fobjc-runtime=gcc 
-fblocks -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fblocks -o - %s | 
FileCheck %s
+
+// Test that descriptor symbol names don't include '@'.
+
+// CHECK: @[[STR:.*]] = private unnamed_addr constant [6 x i8] c"v8@?0\00"
+// CHECK: @"__block_descriptor_40_8_32o_e5_v8\01?0l" = linkonce_odr hidden 
unnamed_addr constant { i64, i64, i8*, i8*, i8*, {{.*}} } { i64 0, i64 40, i8* 
bitcast ({{.*}} to i8*), i8* bitcast ({{.*}} to i8*), i8* getelementptr 
inbounds ([6 x i8], [6 x i8]* @[[STR]], i32 0, i32 0), {{.*}} }, align 8
+
+typedef void (^BlockTy)(void);
+
+void test(id a) {
+  BlockTy b = ^{ (void)a; };
+}
Index: lib/CodeGen/CGBlocks.cpp
===
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -161,6 +161,9 @@
 
   std::string TypeAtEncoding =
   CGM.getContext().getObjCEncodingForBlock(BlockInfo.getBlockExpr());
+  /// Replace occurrences of '@' with '\1'. '@' is reserved on ELF platforms as
+  /// a separator between symbol name and symbol version.
+  std::replace(TypeAtEncoding.begin(), TypeAtEncoding.end(), '@', '\1');
   Name += "e" + llvm::to_string(TypeAtEncoding.size()) + "_" + TypeAtEncoding;
   Name += "l" + CGM.getObjCRuntime().getRCBlockLayoutStr(CGM, BlockInfo);
   return Name;


Index: test/CodeGenObjCXX/block-nested-in-lambda.mm
===
--- test/CodeGenObjCXX/block-nested-in-lambda.mm
+++ test/CodeGenObjCXX/block-nested-in-lambda.mm
@@ -35,7 +35,7 @@
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test0Ev(
 // CHECK-LABEL: define internal void @"_ZZN18CaptureByReference5test0EvENK3$_1clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* @"__block_descriptor_40_e5_v8@?0ls32l8" to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
+// CHECK:

[PATCH] D54539: [CodeGen] Replace '@' characters in block descriptors' symbol names with '\1' on ELF targets.

2018-12-29 Thread David Chisnall via Phabricator via cfe-commits
theraven accepted this revision.
theraven added a comment.
This revision is now accepted and ready to land.

Looks like a much cleaner change.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54539/new/

https://reviews.llvm.org/D54539



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:38
+
+  fclose(fp);
+  return 0;

mgorny wrote:
> krytarowski wrote:
> > krytarowski wrote:
> > > `assert(!fclose(fp));`
> > alternatively `!= EOF`
> It will fail most likely, due to us closing the fd before. However, I'm not 
> sure if we want to strictly rely on this error condition.
Ah, OK. Please just add a comment that this call might fail.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179691.
mgorny added a comment.

Added asserts for `fclose()`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56136/new/

https://reviews.llvm.org/D56136

Files:
  test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
  test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // fclose() will return EBADF because of closed fd
+  assert(fclose(fp) == -1);
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // fclose() will return EBADF because of closed fd
+  assert(fclose(fp) == -1);
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56149: [sanitizer_common] Rewrite fgets/fputs/puts tests to use asserts

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Rewrite the tests for fgets and for fputs/puts to verify results
using assert instead of silently returning non-zero exit status.
This is based on requests made in review of D56136 
.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56149

Files:
  test/sanitizer_common/TestCases/Posix/fgets.cc
  test/sanitizer_common/TestCases/Posix/fputs_puts.cc


Index: test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===
--- test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
 // CHECK: {{^foobar$}}
 
+#include 
 #include 
 
 int main(void) {
-  int r;
-
-  r = fputs("foo", stdout);
-  if (r < 0)
-return 1;
-
-  r = puts("bar");
-  if (r < 0)
-return 1;
+  assert(fputs("foo", stdout) >= 0);
+  assert(puts("bar") >= 0);
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgets.cc
===
--- test/sanitizer_common/TestCases/Posix/fgets.cc
+++ test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
 // RUN: %clangxx -g %s -o %t && %run %t
 
+#include 
 #include 
 
 int main(int argc, char **argv) {
-  FILE *fp;
-  char buf[2];
-  char *s;
-
-  fp = fopen(argv[0], "r");
-  if (!fp)
-return 1;
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
 
-  s = fgets(buf, sizeof(buf), fp);
-  if (!s)
-return 2;
+  char buf[2];
+  char *s = fgets(buf, sizeof(buf), fp);
+  assert(s);
 
-  fclose(fp);
+  assert(!fclose(fp));
   return 0;
 }


Index: test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===
--- test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
 // CHECK: {{^foobar$}}
 
+#include 
 #include 
 
 int main(void) {
-  int r;
-
-  r = fputs("foo", stdout);
-  if (r < 0)
-return 1;
-
-  r = puts("bar");
-  if (r < 0)
-return 1;
+  assert(fputs("foo", stdout) >= 0);
+  assert(puts("bar") >= 0);
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgets.cc
===
--- test/sanitizer_common/TestCases/Posix/fgets.cc
+++ test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
 // RUN: %clangxx -g %s -o %t && %run %t
 
+#include 
 #include 
 
 int main(int argc, char **argv) {
-  FILE *fp;
-  char buf[2];
-  char *s;
-
-  fp = fopen(argv[0], "r");
-  if (!fp)
-return 1;
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
 
-  s = fgets(buf, sizeof(buf), fp);
-  if (!s)
-return 2;
+  char buf[2];
+  char *s = fgets(buf, sizeof(buf), fp);
+  assert(s);
 
-  fclose(fp);
+  assert(!fclose(fp));
   return 0;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56149: [sanitizer_common] Rewrite more Posix tests to use asserts

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179693.
mgorny retitled this revision from "[sanitizer_common] Rewrite fgets/fputs/puts 
tests to use asserts" to "[sanitizer_common] Rewrite more Posix tests to use 
asserts".
mgorny edited the summary of this revision.
mgorny added a comment.

Updated to cover functions which used `exit(1)` too.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56149/new/

https://reviews.llvm.org/D56149

Files:
  test/sanitizer_common/TestCases/Posix/devname.cc
  test/sanitizer_common/TestCases/Posix/devname_r.cc
  test/sanitizer_common/TestCases/Posix/fgetln.cc
  test/sanitizer_common/TestCases/Posix/fgets.cc
  test/sanitizer_common/TestCases/Posix/fputs_puts.cc
  test/sanitizer_common/TestCases/Posix/lstat.cc

Index: test/sanitizer_common/TestCases/Posix/lstat.cc
===
--- test/sanitizer_common/TestCases/Posix/lstat.cc
+++ test/sanitizer_common/TestCases/Posix/lstat.cc
@@ -1,16 +1,14 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t
 
+#include 
 #include 
 #include 
 
 int main(void) {
   struct stat st;
 
-  if (lstat("/dev/null", &st))
-exit(1);
-
-  if (!S_ISCHR(st.st_mode))
-exit(1);
+  assert(!lstat("/dev/null", &st));
+  assert(S_ISCHR(st.st_mode));
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===
--- test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
 // CHECK: {{^foobar$}}
 
+#include 
 #include 
 
 int main(void) {
-  int r;
-
-  r = fputs("foo", stdout);
-  if (r < 0)
-return 1;
-
-  r = puts("bar");
-  if (r < 0)
-return 1;
+  assert(fputs("foo", stdout) >= 0);
+  assert(puts("bar") >= 0);
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgets.cc
===
--- test/sanitizer_common/TestCases/Posix/fgets.cc
+++ test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
 // RUN: %clangxx -g %s -o %t && %run %t
 
+#include 
 #include 
 
 int main(int argc, char **argv) {
-  FILE *fp;
-  char buf[2];
-  char *s;
-
-  fp = fopen(argv[0], "r");
-  if (!fp)
-return 1;
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
 
-  s = fgets(buf, sizeof(buf), fp);
-  if (!s)
-return 2;
+  char buf[2];
+  char *s = fgets(buf, sizeof(buf), fp);
+  assert(s);
 
-  fclose(fp);
+  assert(!fclose(fp));
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgetln.cc
===
--- test/sanitizer_common/TestCases/Posix/fgetln.cc
+++ test/sanitizer_common/TestCases/Posix/fgetln.cc
@@ -1,24 +1,20 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t
 // UNSUPPORTED: linux
 
+#include 
 #include 
 #include 
 
 int main(void) {
-  FILE *fp;
-  size_t len;
-  char *s;
-
-  fp = fopen("/etc/hosts", "r");
-  if (!fp)
-exit(1);
+  FILE *fp = fopen("/etc/hosts", "r");
+  assert(fp);
 
-  s = fgetln(fp, &len);
+  size_t len;
+  char *s = fgetln(fp, &len);
 
   printf("%.*s\n", (int)len, s);
 
-  if (fclose(fp) == EOF)
-exit(1);
+  assert(!fclose(fp));
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/devname_r.cc
===
--- test/sanitizer_common/TestCases/Posix/devname_r.cc
+++ test/sanitizer_common/TestCases/Posix/devname_r.cc
@@ -4,6 +4,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 
@@ -12,17 +13,14 @@
   char name[100];
   mode_t type;
 
-  if (stat("/dev/null", &st))
-exit(1);
+  assert(!stat("/dev/null", &st));
 
   type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK;
 
 #if defined(__NetBSD__)
-  if (devname_r(st.st_rdev, type, name, sizeof(name)))
-exit(1);
+  assert(!devname_r(st.st_rdev, type, name, sizeof(name)));
 #else
-  if (!devname_r(st.st_rdev, type, name, sizeof(name)))
-exit(1);
+  assert(devname_r(st.st_rdev, type, name, sizeof(name)));
 #endif
 
   printf("%s\n", name);
Index: test/sanitizer_common/TestCases/Posix/devname.cc
===
--- test/sanitizer_common/TestCases/Posix/devname.cc
+++ test/sanitizer_common/TestCases/Posix/devname.cc
@@ -1,6 +1,7 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
 // UNSUPPORTED: linux, solaris
 
+#include 
 #include 
 #include 
 #include 
@@ -9,11 +10,8 @@
   struct stat st;
   char *name;
 
-  if (stat("/dev/null", &st))
-exit(1);
-
-  if (!(name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)))
-exit(1);
+  assert(!stat("/dev/null", &st));
+  assert((name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)));
 
   printf("%s\n", name);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-co

[PATCH] D56149: [sanitizer_common] Rewrite more Posix tests to use asserts

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/devname_r.cc:21
 #if defined(__NetBSD__)
-  if (devname_r(st.st_rdev, type, name, sizeof(name)))
-exit(1);
+  assert(!devname_r(st.st_rdev, type, name, sizeof(name)));
 #else

While there.. devname_r has a broken interceptor for !NetBSD. Wrong return type.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56149/new/

https://reviews.llvm.org/D56149



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek, emaste.

Update the interceptor for devname_r() to account for correct return
types on different platforms.  This function returns int on NetBSD
but char* on FreeBSD/OSX.  Noticed by @krytarowski.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56150

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path, uptr 
len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path, uptr len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179696.
mgorny added a comment.

Fixed lint.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56150/new/

https://reviews.llvm.org/D56150

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,20 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,20 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Looks fine, but according to newer style of newer interceptors we prefer: 
`DEVNAME_R_RETTYPE res = REAL(devname_r)(dev, type, path, len);`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56150/new/

https://reviews.llvm.org/D56150



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r350157 - [CodeGen] Replace '@' characters in block descriptors' symbol names with

2018-12-29 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Sat Dec 29 09:28:30 2018
New Revision: 350157

URL: http://llvm.org/viewvc/llvm-project?rev=350157&view=rev
Log:
[CodeGen] Replace '@' characters in block descriptors' symbol names with
'\1'.

'@' can't be used in block descriptors' symbol names since it is
reserved on ELF platforms as a separator between symbol names and symbol
versions.

See the discussion here: https://reviews.llvm.org/D50783.

Differential Revision: https://reviews.llvm.org/D54539

Added:
cfe/trunk/test/CodeGenObjC/block-desc-str.m
Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=350157&r1=350156&r2=350157&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sat Dec 29 09:28:30 2018
@@ -161,6 +161,9 @@ static std::string getBlockDescriptorNam
 
   std::string TypeAtEncoding =
   CGM.getContext().getObjCEncodingForBlock(BlockInfo.getBlockExpr());
+  /// Replace occurrences of '@' with '\1'. '@' is reserved on ELF platforms as
+  /// a separator between symbol name and symbol version.
+  std::replace(TypeAtEncoding.begin(), TypeAtEncoding.end(), '@', '\1');
   Name += "e" + llvm::to_string(TypeAtEncoding.size()) + "_" + TypeAtEncoding;
   Name += "l" + CGM.getObjCRuntime().getRCBlockLayoutStr(CGM, BlockInfo);
   return Name;

Added: cfe/trunk/test/CodeGenObjC/block-desc-str.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/block-desc-str.m?rev=350157&view=auto
==
--- cfe/trunk/test/CodeGenObjC/block-desc-str.m (added)
+++ cfe/trunk/test/CodeGenObjC/block-desc-str.m Sat Dec 29 09:28:30 2018
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -emit-llvm 
-fobjc-runtime=gnustep-1.7 -fblocks -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fobjc-runtime=gcc 
-fblocks -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fblocks -o - %s | 
FileCheck %s
+
+// Test that descriptor symbol names don't include '@'.
+
+// CHECK: @[[STR:.*]] = private unnamed_addr constant [6 x i8] c"v8@?0\00"
+// CHECK: @"__block_descriptor_40_8_32o_e5_v8\01?0l" = linkonce_odr hidden 
unnamed_addr constant { i64, i64, i8*, i8*, i8*, {{.*}} } { i64 0, i64 40, i8* 
bitcast ({{.*}} to i8*), i8* bitcast ({{.*}} to i8*), i8* getelementptr 
inbounds ([6 x i8], [6 x i8]* @[[STR]], i32 0, i32 0), {{.*}} }, align 8
+
+typedef void (^BlockTy)(void);
+
+void test(id a) {
+  BlockTy b = ^{ (void)a; };
+}

Modified: cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm?rev=350157&r1=350156&r2=350157&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm Sat Dec 29 09:28:30 
2018
@@ -35,7 +35,7 @@ void use(id);
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test0Ev(
 // CHECK-LABEL: define internal void 
@"_ZZN18CaptureByReference5test0EvENK3$_1clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* 
@"__block_descriptor_40_e5_v8@?0ls32l8" to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* 
@"__block_descriptor_40_e5_v8\01?0ls32l8" to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
 
 void test0() {
   id a = getObj();
@@ -48,7 +48,7 @@ void test0() {
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test1Ev(
 // CHECK-LABEL: define internal void 
@"_ZZN18CaptureByReference5test1EvENK3$_2clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8** }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8** }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i64 }* @"__block_descriptor_56_8_32s40s_e5_v8@?0l" to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 8
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i64 }* @"__block_descriptor_56_8_32s40s_e5_v8\01?0l" to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 8
 
 // CHECK-

[PATCH] D54539: [CodeGen] Replace '@' characters in block descriptors' symbol names with '\1' on ELF targets.

2018-12-29 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350157: [CodeGen] Replace '@' characters in block 
descriptors' symbol names with (authored by ahatanak, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D54539?vs=179676&id=179697#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54539/new/

https://reviews.llvm.org/D54539

Files:
  cfe/trunk/lib/CodeGen/CGBlocks.cpp
  cfe/trunk/test/CodeGenObjC/block-desc-str.m
  cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm


Index: cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
===
--- cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
+++ cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
@@ -35,7 +35,7 @@
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test0Ev(
 // CHECK-LABEL: define internal void 
@"_ZZN18CaptureByReference5test0EvENK3$_1clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* 
@"__block_descriptor_40_e5_v8@?0ls32l8" to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* 
@"__block_descriptor_40_e5_v8\01?0ls32l8" to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
 
 void test0() {
   id a = getObj();
@@ -48,7 +48,7 @@
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test1Ev(
 // CHECK-LABEL: define internal void 
@"_ZZN18CaptureByReference5test1EvENK3$_2clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8** }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8** }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i64 }* @"__block_descriptor_56_8_32s40s_e5_v8@?0l" to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 8
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i64 }* @"__block_descriptor_56_8_32s40s_e5_v8\01?0l" to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 8
 
 // CHECK-LABEL: define linkonce_odr hidden void @__copy_helper_block_8_32s40s(
 // CHECK-NOT: call void @llvm.objc.storeStrong(
Index: cfe/trunk/test/CodeGenObjC/block-desc-str.m
===
--- cfe/trunk/test/CodeGenObjC/block-desc-str.m
+++ cfe/trunk/test/CodeGenObjC/block-desc-str.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -emit-llvm 
-fobjc-runtime=gnustep-1.7 -fblocks -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fobjc-runtime=gcc 
-fblocks -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fblocks -o - %s | 
FileCheck %s
+
+// Test that descriptor symbol names don't include '@'.
+
+// CHECK: @[[STR:.*]] = private unnamed_addr constant [6 x i8] c"v8@?0\00"
+// CHECK: @"__block_descriptor_40_8_32o_e5_v8\01?0l" = linkonce_odr hidden 
unnamed_addr constant { i64, i64, i8*, i8*, i8*, {{.*}} } { i64 0, i64 40, i8* 
bitcast ({{.*}} to i8*), i8* bitcast ({{.*}} to i8*), i8* getelementptr 
inbounds ([6 x i8], [6 x i8]* @[[STR]], i32 0, i32 0), {{.*}} }, align 8
+
+typedef void (^BlockTy)(void);
+
+void test(id a) {
+  BlockTy b = ^{ (void)a; };
+}
Index: cfe/trunk/lib/CodeGen/CGBlocks.cpp
===
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp
@@ -161,6 +161,9 @@
 
   std::string TypeAtEncoding =
   CGM.getContext().getObjCEncodingForBlock(BlockInfo.getBlockExpr());
+  /// Replace occurrences of '@' with '\1'. '@' is reserved on ELF platforms as
+  /// a separator between symbol name and symbol version.
+  std::replace(TypeAtEncoding.begin(), TypeAtEncoding.end(), '@', '\1');
   Name += "e" + llvm::to_string(TypeAtEncoding.size()) + "_" + TypeAtEncoding;
   Name += "l" + CGM.getObjCRuntime().getRCBlockLayoutStr(CGM, BlockInfo);
   return Name;


Index: cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
===
--- cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
+++ cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
@@ -35,7 +35,7 @@
 // CHECK-LABEL: define void @_ZN18CaptureByReference5test0Ev(
 // CHECK-LABEL: define internal void @"_ZZN18CaptureByReference5test0EvENK3$_1clEv"(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32

[PATCH] D56152: [sanitizer_common] Add tests for remaining *putc and *getc variants

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Subject: [PATCH 5/5] [sanitizer_common] Add tests for remaining *putc and
 *getc variants

Add tests for the remaining character-oriented functions, that is:

- fputc(), putc() and putchar()
- getc_unlocked()
- putc_unlocked() and putchar_unlocked()

I'm omitting getchar_unlocked() as it relies on reading from stdin,
and it is unlikely for it to be implemented otherwise as an alias
to getc/fgetc.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56152

Files:
  test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
  test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
  test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56153: [sanitizer_common] Add test for popen()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56153

Files:
  test/sanitizer_common/TestCases/Posix/popen.cc


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56153: [sanitizer_common] Add test for popen()

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

It looks fine, but we don't have interceptors for popen(3), popenve(3), 
pclose(3). Could you include them together with this patch? Add add a test for 
popenve(3).


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56153/new/

https://reviews.llvm.org/D56153



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56152: [sanitizer_common] Add tests for remaining *putc and *getc variants

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Are all the functions available for FreeBSD, NetBSD, Linux, Android, Solaris an 
Darwin?

I would include a test for `getchar_unlocked()` anyway, even if it's an alias 
in most/all implementations.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56152/new/

https://reviews.llvm.org/D56152



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56154: [sanitizer_common] Add tests for NetBSD funopen*()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56154

Files:
  test/sanitizer_common/TestCases/NetBSD/funopen.cc
  test/sanitizer_common/TestCases/NetBSD/funopen2.cc

Index: test/sanitizer_common/TestCases/NetBSD/funopen2.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen2.cc
@@ -0,0 +1,104 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+ssize_t f_read(void *cookie, void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%zd\n", len);
+  return strlcpy((char*)buf, "test\n", len);
+}
+
+ssize_t f_write(void *cookie, const void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup((char*)buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_flush(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("FLUSH CALLED\n");
+  return 0;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen2(&cookie_var, f_read);
+  assert(fp);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 2. write-only variant
+  fp = fwopen2(&cookie_var, f_write);
+  assert(fp);
+  assert(fputs("test", fp) >= 0);
+  assert(!fclose(fp));
+
+  // 3. read+write+close
+  fp = funopen2(&cookie_var, f_read, f_write, NULL, NULL, f_close);
+  assert(fp);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(!fclose(fp));
+
+  // 4. read+seek
+  fp = funopen2(&cookie_var, f_read, NULL, f_seek, NULL, NULL);
+  assert(fp);
+  assert(fseek(fp, 100, SEEK_SET) == 0);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 5. write+flush
+  fp = funopen2(&cookie_var, NULL, f_write, NULL, f_flush, NULL);
+  assert(fp);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(fputs("test", fp) >= 0);
+  // NB: fclose() also implicitly calls flush
+  assert(!fclose(fp));
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/NetBSD/funopen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen.cc
@@ -0,0 +1,84 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+int f_read(void *cookie, char *buf, int len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%d\n", len);
+  return strlcpy(buf, "test\n", len);
+}
+
+int f_write(void *cookie, const char *buf, int len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup(buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen(&cookie_var, f_read);
+  assert(fp);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 2. write-only variant
+  fp = fwopen(&cookie_var, f_write);
+  assert(fp);
+  assert(fputs("test", fp) >= 0);
+  assert(!fclose(fp));
+
+  // 3. read+write+close
+  fp = funopen(&cookie_var, f_read, f_write, NULL

[PATCH] D56152: [sanitizer_common] Add tests for remaining *putc and *getc variants

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Does this depend on D56109 ?

It looks like we shall install interceptors for a lot of routines that are 
FILE* users.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56152/new/

https://reviews.llvm.org/D56152



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56154: [sanitizer_common] Add tests for NetBSD funopen*()

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added inline comments.



Comment at: test/sanitizer_common/TestCases/NetBSD/funopen2.cc:2
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}

// UNSUPPORTED: linux, freebsd, solaris, darwin


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56154/new/

https://reviews.llvm.org/D56154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56154: [sanitizer_common] Add tests for NetBSD funopen*()

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski accepted this revision.
krytarowski added inline comments.
This revision is now accepted and ready to land.



Comment at: test/sanitizer_common/TestCases/NetBSD/funopen2.cc:2
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}

krytarowski wrote:
> // UNSUPPORTED: linux, freebsd, solaris, darwin
Ah, it's already in NetBSD/, so it's fine.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56154/new/

https://reviews.llvm.org/D56154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56153: [sanitizer_common] Add test for popen()

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski accepted this revision.
krytarowski added a comment.
This revision is now accepted and ready to land.

But of course new code can be added as a new revision.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56153/new/

https://reviews.llvm.org/D56153



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2018-12-29 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

In D53072#1268883 , @yvvan wrote:

> Do you know the better way to accomplish my aim than adding an option to 
> libFormat? For example making a dependent library which serves a little 
> different purpose than libFormat itself or something simpler?


I don't know about the specific use-case, but in general a fail-safe way to 
force a line break in C++ code is to add an empty line comment on the preceding 
line.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53072/new/

https://reviews.llvm.org/D53072



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2018-12-29 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D33499#1341236 , 
@ken-cunningham-webuse wrote:

> @iains - I have interest in resolving this issue, and also a couple of other 
> lingering bugs in the PPC32Darwin ABI realm. If you have your WIP available 
> anywhere, I'd be happy to have a go at bringing it up to current.


A decision was made a while ago to remove Darwin support from the PPC back end. 
This was decided due to very little use of the code and essentially no 
maintenance being done on it. I think that support was already turned off in 
ToT with the plan to slowly rip out the code over the next couple of releases. 
So I believe that any improvements you plan to make it will need to be done on 
an older release out of tree unless you can make a compelling case for keeping 
this support in LLVM. Tagging some of the interested parties (@kbarton @hfinkel 
@echristo).


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D33499/new/

https://reviews.llvm.org/D33499



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2018-12-29 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

Since that's my understanding too - I am (slowly) bringing my patches forward 
to 7.0 - at the moment testing the MC layer changes on powerpc-darwin9 (looking 
reasonable, as an assembler for GCC, so far).   When things are "ready" (at 
least not broken as far as I can tell) - will push them to my github (iains).

I think the parting comment was that if /when it's coherent enough to warrant 
re-inclusion (or there are enough developer cycles to maintain it)... then that 
could be discussed.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D33499/new/

https://reviews.llvm.org/D33499



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2018-12-29 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

I don't quite understand. What you are describing should already be the 
behavior with ColumnLimit=0 and I think your test should pass without the new 
option. Doesn't it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53072/new/

https://reviews.llvm.org/D53072



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56152: [sanitizer_common] Add tests for remaining *putc and *getc variants

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D56152#1342331 , @krytarowski wrote:

> Are all the functions available for FreeBSD, NetBSD, Linux, Android, Solaris 
> an Darwin?


I don't know. I suppose the easiest way to check would be to commit it and see 
what happens. Then address the fallout.

> I would include a test for `getchar_unlocked()` anyway, even if it's an alias 
> in most/all implementations.

I suppose I could do that but I'd have to pipe some data into the stdin.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56152/new/

https://reviews.llvm.org/D56152



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47344: LWG 2843 "Unclear behavior of std::pmr::memory_resource::do_allocate()"

2018-12-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@EricWF ping!


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D47344/new/

https://reviews.llvm.org/D47344



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179707.
mgorny added a comment.

Updated variable style.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56150/new/

https://reviews.llvm.org/D56150

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
-  res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  DEVNAME_R_RETTYPE res = REAL(devname_r)(dev, type, path, len);
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
-  res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  DEVNAME_R_RETTYPE res = REAL(devname_r)(dev, type, path, len);
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2018-12-29 Thread Ken Cunningham via Phabricator via cfe-commits
ken-cunningham-webuse added a comment.

I saw that idea floated but didn't see that it was accepted. I don't know 
exactly how much interest there is in darwin PPC. There are new tickets about 
Darwin PPC within the past few months. I see plenty of questions about it on 
the MacPorts boards.

I have clang/llvm-5.0 and clang/llvm-3.8 running now on 10.5 PPC with a 98% 
pass on the test suite. I use it to build things on a daily basis. The 
compiler_rt build is messy still, otherwise I would push it to MacPorts now.

AFAICT, darwin PPC is missing only support for non-default exceptions (there is 
a ticket about that), and this va_args thing. Everything else seems to be 
working and intact.

I have the patch in this ticket already incorporated in my builds.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D33499/new/

https://reviews.llvm.org/D33499



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55326: [Driver] Fix incorrect GNU triplet for PowerPC on SUSE Linux

2018-12-29 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai requested changes to this revision.
nemanjai added a comment.
This revision now requires changes to proceed.

A couple of questions since I am not all that familiar with clang and am 
certainly not familiar with this unusual SUSE 32-bit situation:

- We seem to be changing the set of aliases here, but what happens if someone 
actually explicitly specifies `--target=powerpc-suse-linux`?
- Do we need to change anything about include paths?
- Can you describe the default triple for clang on SUSE 32-bit PPC? Will it be 
`powerpc-suse-linux`? `powerpc64-suse-linux`?
- Will this change not affect 64-bit PPC SUSE? Namely will the default 
libraries on actual 64-bit PPC SUSE big endian systems now be 32-bit libraries?
- Can you please add a test case and a patch with full context before this 
patch can go any further?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55326/new/

https://reviews.llvm.org/D55326



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56157: [sanitizer_common] Implement popen, popenve, pclose interceptors

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Implement the interceptors for popen(), pclose() and popenve()
functions.  The first two are POSIX, the third one is specific
to NetBSD.  popen() spawns a process and creates a FILE object piping
data from/to that process.  pclose() closes the pipe and waits for
the process to terminate appropriately.

For the purpose of popen(), a new COMMON_INTERCEPTOR_PIPE_OPEN macro is
added that is like COMMON_INTERCEPTOR_FILE_OPEN, except it is passed
the new FILE* and no path.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56157

Files:
  lib/esan/esan_interceptors.cpp
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -2256,6 +2256,12 @@
 if (fd >= 0) FdFileCreate(thr, pc, fd);   \
   }
 
+#define COMMON_INTERCEPTOR_PIPE_OPEN(ctx, file) \
+  if (file) {   \
+int fd = fileno_unlocked(file); \
+if (fd >= 0) FdFileCreate(thr, pc, fd); \
+  }
+
 #define COMMON_INTERCEPTOR_FILE_CLOSE(ctx, file) \
   if (file) {\
 int fd = fileno_unlocked(file);  \
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -546,4 +546,8 @@
 #define SANITIZER_INTERCEPT_CDB SI_NETBSD
 #define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD)
 
+#define SANITIZER_INTERCEPT_POPEN SI_POSIX
+#define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
+#define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -178,6 +178,10 @@
 #define COMMON_INTERCEPTOR_FILE_OPEN(ctx, file, path) {}
 #endif
 
+#ifndef COMMON_INTERCEPTOR_PIPE_OPEN
+#define COMMON_INTERCEPTOR_PIPE_OPEN(ctx, file) {}
+#endif
+
 #ifndef COMMON_INTERCEPTOR_FILE_CLOSE
 #define COMMON_INTERCEPTOR_FILE_CLOSE(ctx, file) {}
 #endif
@@ -9058,6 +9062,77 @@
 #define INIT_CDB
 #endif
 
+#if SANITIZER_INTERCEPT_POPEN
+INTERCEPTOR(__sanitizer_FILE *, popen, const char *command, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popen, command, type);
+  if (command)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, command, REAL(strlen)(command) + 1);
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popen)(command, type);
+  COMMON_INTERCEPTOR_PIPE_OPEN(ctx, res);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPEN COMMON_INTERCEPT_FUNCTION(popen)
+#else
+#define INIT_POPEN
+#endif
+
+#if SANITIZER_INTERCEPT_POPENVE
+INTERCEPTOR(__sanitizer_FILE *, popenve, const char *path,
+char *const *argv, char *const *envp, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popenve, path, argv, envp, type);
+  if (path)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  if (argv) {
+for (char *const *pa = argv; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (envp) {
+for (char *const *pa = envp; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popenve)(path, argv, envp, type);
+  COMMON_INTERCEPTOR_PIPE_OPEN(ctx, res);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPENVE COMMON_INTERCEPT_FUNCTION(popenve)
+#else
+#define INIT_POPENVE
+#endif
+
+#if SANITIZER_INTERCEPT_PCLOSE
+INTERCEPTOR(int, pclose, __sanitizer_FILE *fp) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, pclose, fp);
+  COMMON_INTERCEPTOR_FILE_CLOSE(ctx, fp);
+  const FileMetadata *m = GetInterceptorMetadata(fp);
+  int res = REAL(pclose)(fp);
+  if (m) {
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(*m->addr, *m->size);
+DeleteInterceptorMetadata(fp);
+  }
+  return res;
+}
+#define INIT_PCLOSE COMMON_INTERCEPT_FUNCTION(pclose);
+#else
+#define INIT_PCLOSE
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(Metadata

[PATCH] D47344: LWG 2843 "Unclear behavior of std::pmr::memory_resource::do_allocate()"

2018-12-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 179710.

Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D47344/new/

https://reviews.llvm.org/D47344

Files:
  src/experimental/memory_resource.cpp


Index: src/experimental/memory_resource.cpp
===
--- src/experimental/memory_resource.cpp
+++ src/experimental/memory_resource.cpp
@@ -26,19 +26,20 @@
 class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
 : public memory_resource
 {
-public:
-~__new_delete_memory_resource_imp() = default;
-
-protected:
-virtual void* do_allocate(size_t __size, size_t __align)
-{ return _VSTD::__libcpp_allocate(__size, __align); /* FIXME */}
+void *do_allocate(size_t size, size_t align) override {
+#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+if (__is_overaligned_for_new(align))
+__throw_bad_alloc();
+#endif
+return _VSTD::__libcpp_allocate(size, align);
+}
 
-virtual void do_deallocate(void* __p, size_t __n, size_t __align) {
-  _VSTD::__libcpp_deallocate(__p, __n, __align); /* FIXME */
+void do_deallocate(void *p, size_t n, size_t align) override {
+  _VSTD::__libcpp_deallocate(p, n, align);
 }
 
-virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
-{ return &__other == this; }
+bool do_is_equal(memory_resource const & other) const _NOEXCEPT override
+{ return &other == this; }
 };
 
 // null_memory_resource()


Index: src/experimental/memory_resource.cpp
===
--- src/experimental/memory_resource.cpp
+++ src/experimental/memory_resource.cpp
@@ -26,19 +26,20 @@
 class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
 : public memory_resource
 {
-public:
-~__new_delete_memory_resource_imp() = default;
-
-protected:
-virtual void* do_allocate(size_t __size, size_t __align)
-{ return _VSTD::__libcpp_allocate(__size, __align); /* FIXME */}
+void *do_allocate(size_t size, size_t align) override {
+#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+if (__is_overaligned_for_new(align))
+__throw_bad_alloc();
+#endif
+return _VSTD::__libcpp_allocate(size, align);
+}
 
-virtual void do_deallocate(void* __p, size_t __n, size_t __align) {
-  _VSTD::__libcpp_deallocate(__p, __n, __align); /* FIXME */
+void do_deallocate(void *p, size_t n, size_t align) override {
+  _VSTD::__libcpp_deallocate(p, n, align);
 }
 
-virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
-{ return &__other == this; }
+bool do_is_equal(memory_resource const & other) const _NOEXCEPT override
+{ return &other == this; }
 };
 
 // null_memory_resource()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56157: [sanitizer_common] Implement popen, popenve, pclose interceptors

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a subscriber: dvyukov.
krytarowski added a comment.

Looks good to me, but it would be nice to have opinion of @vitalybuka and/or 
@dvyukov (TSan).


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56157/new/

https://reviews.llvm.org/D56157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56152: [sanitizer_common] Add tests for remaining *putc and *getc variants

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski accepted this revision.
krytarowski added a comment.
This revision is now accepted and ready to land.

In D56152#1342372 , @mgorny wrote:

> In D56152#1342331 , @krytarowski 
> wrote:
>
> > Are all the functions available for FreeBSD, NetBSD, Linux, Android, 
> > Solaris an Darwin?
>
>
> I don't know. I suppose the easiest way to check would be to commit it and 
> see what happens. Then address the fallout.
>
> > I would include a test for `getchar_unlocked()` anyway, even if it's an 
> > alias in most/all implementations.
>
> I suppose I could do that but I'd have to pipe some data into the stdin.


OK, so let's do it in another test.

Please drop its mention in description.


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56152/new/

https://reviews.llvm.org/D56152



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55326: [Driver] Fix incorrect GNU triplet for PowerPC on SUSE Linux

2018-12-29 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D55326#1342412 , @nemanjai wrote:

> A couple of questions since I am not all that familiar with clang and am 
> certainly not familiar with this unusual SUSE 32-bit situation:
>
> - We seem to be changing the set of aliases here, but what happens if someone 
> actually explicitly specifies `--target=powerpc-suse-linux`?


This is just the name of GCCDIST that is adjusted.

> - Do we need to change anything about include paths?

No.

On an openSUSE machine on ppc, we have:

  :/usr # ls -l /usr/lib/gcc/
  total 0
  drwxr-xr-x 3 root root 15 Nov 19 23:27 powerpc64-suse-linux
  :/usr # ls -dl /usr/power*
  drwxr-xr-x 5 root root 43 May 25  2018 /usr/powerpc-suse-linux
  :/usr #



> - Can you describe the default triple for clang on SUSE 32-bit PPC? Will it 
> be `powerpc-suse-linux`? `powerpc64-suse-linux`?

I have to verify this.

> - Will this change not affect 64-bit PPC SUSE? Namely will the default 
> libraries on actual 64-bit PPC SUSE big endian systems now be 32-bit 
> libraries?

No. There are separate compiler packages for ppc64 and ppc.

> - Can you please add a test case and a patch with full context before this 
> patch can go any further?

Not sure what the proper test would be.

On a sidenote, the spec file for gcc8 in openSUSE has:

  %define HOST_ARCH %(echo %{_host_cpu} | sed -e 
"s/i.86/i586/;s/ppc/powerpc/;s/sparc64.*/sparc64/;s/sparcv.*/sparc/;")
  %ifarch ppc
  %define GCCDIST powerpc64-suse-linux
  %else
  %ifarch %sparc
  %define GCCDIST sparc64-suse-linux
  %else
  %ifarch %arm
  %define GCCDIST %{HOST_ARCH}-suse-linux-gnueabi
  %else
  %define GCCDIST %{HOST_ARCH}-suse-linux
  %endif
  %endif
  %endif

See: 
https://build.opensuse.org/package/view_file/devel:gcc/gcc8/gcc8.spec?expand=1

So, it's explicitly overriding GCCDIST on ppc to be powerpc64-suse-linux.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55326/new/

https://reviews.llvm.org/D55326



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56152: [sanitizer_common] Add tests for more *putc and *getc variants

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179711.
mgorny retitled this revision from "[sanitizer_common] Add tests for remaining 
*putc and *getc variants" to "[sanitizer_common] Add tests for more *putc and 
*getc variants".
mgorny edited the summary of this revision.
mgorny added a comment.

Updated description.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56152/new/

https://reviews.llvm.org/D56152

Files:
  test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
  test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
  test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56153: [sanitizer_common] Add test for popen()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179712.
mgorny added a comment.

Added assertion verifying that `fileno(fp)` works.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56153/new/

https://reviews.llvm.org/D56153

Files:
  test/sanitizer_common/TestCases/Posix/popen.cc


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+
+  // verify that fileno() returns a meaningful descriptor (needed
+  // for the implementation of TSan)
+  assert(fileno(fp) != -1);
+
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+
+  // verify that fileno() returns a meaningful descriptor (needed
+  // for the implementation of TSan)
+  assert(fileno(fp) != -1);
+
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56154: [sanitizer_common] Add tests for NetBSD funopen*()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179713.
mgorny added a comment.

Added assertions for `fileno()` returning -1.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56154/new/

https://reviews.llvm.org/D56154

Files:
  test/sanitizer_common/TestCases/NetBSD/funopen.cc
  test/sanitizer_common/TestCases/NetBSD/funopen2.cc

Index: test/sanitizer_common/TestCases/NetBSD/funopen2.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen2.cc
@@ -0,0 +1,110 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+ssize_t f_read(void *cookie, void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%zd\n", len);
+  return strlcpy((char*)buf, "test\n", len);
+}
+
+ssize_t f_write(void *cookie, const void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup((char*)buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_flush(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("FLUSH CALLED\n");
+  return 0;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen2(&cookie_var, f_read);
+  assert(fp);
+  // verify that fileno() does not crash or report nonsense
+  assert(fileno(fp) == -1);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 2. write-only variant
+  fp = fwopen2(&cookie_var, f_write);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fputs("test", fp) >= 0);
+  assert(!fclose(fp));
+
+  // 3. read+write+close
+  fp = funopen2(&cookie_var, f_read, f_write, NULL, NULL, f_close);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(!fclose(fp));
+
+  // 4. read+seek
+  fp = funopen2(&cookie_var, f_read, NULL, f_seek, NULL, NULL);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fseek(fp, 100, SEEK_SET) == 0);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 5. write+flush
+  fp = funopen2(&cookie_var, NULL, f_write, NULL, f_flush, NULL);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(fputs("test", fp) >= 0);
+  // NB: fclose() also implicitly calls flush
+  assert(!fclose(fp));
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/NetBSD/funopen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen.cc
@@ -0,0 +1,89 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+int f_read(void *cookie, char *buf, int len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%d\n", len);
+  return strlcpy(buf, "test\n", len);
+}
+
+int f_write(void *cookie, const char *buf, int len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup(buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen(&cookie_var, f_read);
+  assert(fp);
+  // verify that fileno() does not crash or report nonsense
+  assert(fileno(fp) == -1);
+  assert(fge

[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56158

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h


Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,45 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie,
+int (*readfn)(void *cookie, char *buf, int len),
+int (*writefn)(void *cookie, const char *buf, int len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen)(cookie, readfn, writefn, seekfn,
+closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+INTERCEPTOR(__sanitizer_FILE *, funopen2, void *cookie,
+SSIZE_T (*readfn)(void *cookie, void *buf, SIZE_T len),
+SSIZE_T (*writefn)(void *cookie, const void *buf, SIZE_T len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*flushfn)(void *cookie),
+int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen2, cookie, readfn, writefn,
+   seekfn, flushfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen2)(cookie, readfn, writefn, seekfn,
+ flushfn, closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN2 COMMON_INTERCEPT_FUNCTION(funopen2)
+#else
+#define INIT_FUNOPEN2
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map =
@@ -9416,6 +9455,8 @@
   INIT_POPEN;
   INIT_POPENVE;
   INIT_PCLOSE;
+  INIT_FUNOPEN;
+  INIT_FUNOPEN2;
 
   INIT___PRINTF_CHK;
 }


Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,45 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie,
+int (*readfn)(void *cookie, char *buf, int len),
+int (*writefn)(void *cookie, const char *buf, int len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen)(cookie, readfn, writefn, seekfn,
+closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+INTERCEPTOR(__sanitizer_FILE *, funopen2, void *cookie,
+SSIZE_T (*readfn)(void *cookie, void *buf, SIZE_T len),
+SSIZE_T (*writefn)(void *cookie, const void *buf, SIZE_T len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*flushfn)(void *cookie),
+int (*closefn)(void *cookie)) {
+  

[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Shouldn't this follow SANITIZER_INTERCEPT_FOPENCOOKIE and implement a wrapper 
for operations?


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

https://reviews.llvm.org/D56158



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47111: : Implement monotonic_buffer_resource.

2018-12-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 179718.
Quuxplusone added a comment.

Updated and addressed review comments.
`test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_overaligned_request.pass.cpp`
 is now XFAILed on OSX platforms, using code copied-and-pasted from 
`test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp`.

@EricWF ping!


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D47111/new/

https://reviews.llvm.org/D47111

Files:
  include/experimental/memory_resource
  src/experimental/memory_resource.cpp
  
test/libcxx/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_in_geometric_progression.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/copy_move.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/with_default_resource.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/without_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_deallocate.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_exception_safety.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_initial_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_underaligned_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_zero_sized_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_in_geometric_progression.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_overaligned_request.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_with_initial_size.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp

Index: test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
@@ -0,0 +1,62 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// REQUIRES: c++experimental
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// class monotonic_buffer_resource
+
+#include 
+#include 
+#include 
+#include 
+
+struct assert_on_compare : public std::experimental::pmr::memory_resource
+{
+protected:
+void *do_allocate(size_t, size_t)
+{ assert(false); }
+
+void do_deallocate(void *, size_t, size_t)
+{ assert(false); }
+
+bool do_is_equal(std::experimental::pmr::memory_resource const &) const noexcept
+{ assert(false); }
+};
+
+int main()
+{
+// Same object
+{
+std::experimental::pmr::monotonic_buffer_resource r1;
+std::experimental::pmr::monotonic_buffer_resource r2;
+assert(r1 == r1);
+assert(r1 != r2);
+
+std::experimental::pmr::memory_resource & p1 = r1;
+std::experimental::pmr::memory_resource & p2 = r2;
+assert(p1 == p1);
+assert(p1 != p2);
+assert(p1 == r1);
+assert(r1 == p1);
+assert(p1 != r2);
+assert(r2 != p1);
+}
+// Different types
+{
+std::experimental::pmr::monotonic_buffer_resource mono1;
+std::experimental::pmr::memory_resource & r1 = mono1;
+assert_on_compare c;
+std::experimental::pmr::memory_resource & r2 = c;
+assert(r1 != r2);
+assert(!(r1 == r2));
+}
+}
Index: test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_with_initial_size.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_with_initial_size.pass.cpp
@@ -0,0 +1,51 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// REQUIRES: c++experimental
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// class monotonic_buffer_resource

[PATCH] D47111: : Implement monotonic_buffer_resource.

2018-12-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@EricWF ping!
and oops, I never submitted these comments, I guess.




Comment at: include/experimental/memory_resource:427
+{
+static const size_t __default_buffer_capacity = 1024;
+static const size_t __default_buffer_alignment = 16;

EricWF wrote:
> `constexpr` these constants if they're const?
Compare ``, which has "constexpr" in the synopsis comment but "static 
const" in the code.
However, I updated the diff to follow ``'s example and use `static 
_LIBCPP_CONSTEXPR const` everywhere.



Comment at: 
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_overaligned_request.pass.cpp:32
+void *ret = r1.allocate(2048, big_alignment);
+assert(ret != nullptr);
+assert(globalMemCounter.checkNewCalledEq(1));

EricWF wrote:
> This check isn't passing with ToT clang.
Agreed, it won't pass unless the underlying `new_delete_resource` supports 
overaligned alignments, which isn't true unless the underlying runtime supports 
aligned new. Which isn't true on my MacBook.

I think the fix would be for me to copy all the XFAIL lines from 
`test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp`, is 
that right?


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D47111/new/

https://reviews.llvm.org/D47111



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits