summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2019-07-25 22:23:40 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2019-07-25 22:23:40 +0000
commit9d045a5c1e6b7b32cec8bcf140e5bffa5ac812bd (patch)
tree9a9d76c2f39b252b739eb5c8812fb638f0f77c03 /clang/test
parent29af3b4e67713e929b3022d96c8e54408ed9cf46 (diff)
downloadbcm5719-llvm-9d045a5c1e6b7b32cec8bcf140e5bffa5ac812bd.tar.gz
bcm5719-llvm-9d045a5c1e6b7b32cec8bcf140e5bffa5ac812bd.zip
[Sema] add -Walloca to flag uses of `alloca`
This CL adds an optional warning to diagnose uses of the `__builtin_alloca` family of functions. The use of these functions is discouraged by many, so it seems like a good idea to allow clang to warn about it. Patch by Elaina Guan! Differential Revision: https://reviews.llvm.org/D64883 llvm-svn: 367067
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Sema/warn-alloca.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/test/Sema/warn-alloca.c b/clang/test/Sema/warn-alloca.c
new file mode 100644
index 00000000000..0990e11ef2f
--- /dev/null
+++ b/clang/test/Sema/warn-alloca.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSILENCE -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloca %s
+
+#ifdef SILENCE
+ // expected-no-diagnostics
+#endif
+
+void test1(int a) {
+ __builtin_alloca(a);
+#ifndef SILENCE
+ // expected-warning@-2 {{use of function '__builtin_alloca' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test2(int a) {
+ __builtin_alloca_with_align(a, 32);
+#ifndef SILENCE
+ // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
OpenPOWER on IntegriCloud