[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] 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] 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] 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] 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