Module Name: src
Committed By: rillig
Date: Tue Mar 16 23:18:49 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_139.c msg_139.exp
Log Message:
tests/lint: add test for message 139 about division by zero
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_139.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_139.exp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/msg_139.c
diff -u src/tests/usr.bin/xlint/lint1/msg_139.c:1.2 src/tests/usr.bin/xlint/lint1/msg_139.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_139.c:1.2 Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_139.c Tue Mar 16 23:18:49 2021
@@ -1,7 +1,24 @@
-/* $NetBSD: msg_139.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_139.c,v 1.3 2021/03/16 23:18:49 rillig Exp $ */
# 3 "msg_139.c"
// Test for message: division by 0 [139]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void sink_int(int);
+void sink_double(double);
+
+void
+example(int i)
+{
+ enum {
+ zero = 0
+ };
+
+ sink_int(i / 0); /* only triggers in constant expressions */
+ sink_int(i / zero); /* only triggers in constant expressions */
+ sink_double(i / 0.0);
+
+ sink_int(13 / 0); /* expect: 139 */
+ sink_int(13 / zero); /* expect: 139 */
+ sink_double(13 / 0.0); /* expect: 139 *//* XXX: Clang doesn't warn */
+ sink_double(13 / -0.0); /* expect: 139 *//* XXX: Clang doesn't warn */
+}
Index: src/tests/usr.bin/xlint/lint1/msg_139.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_139.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_139.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_139.exp:1.1 Sat Jan 2 10:22:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_139.exp Tue Mar 16 23:18:49 2021
@@ -1 +1,4 @@
-msg_139.c(6): syntax error ':' [249]
+msg_139.c(20): division by 0 [139]
+msg_139.c(21): division by 0 [139]
+msg_139.c(22): division by 0 [139]
+msg_139.c(23): division by 0 [139]