summaryrefslogtreecommitdiffstats
path: root/tests/preprocessor/pragma-warning
diff options
context:
space:
mode:
authorRonan <ro.cailleau@gmail.com>2025-04-25 00:48:37 +0200
committerGitHub <noreply@github.com>2025-04-24 15:48:37 -0700
commit5f632cd204b7a85f3a97b6c316c5a34f9fc8193e (patch)
tree7dc74fbe8c80870a4c485bbaa5765ff379914779 /tests/preprocessor/pragma-warning
parentc7ecf3039d2cc8680f1ea5f4bee2d13521ae34f7 (diff)
Implemented #pragma warning (#6748)
* Implemented #pragma warning Based on https://learn.microsoft.com/en-us/cpp/preprocessor/warning?view=msvc-170 * Make #pragma warning work with #includes. - SourceLoc are not sorted by inclusion order. - Construct a mapping from SourceLoc to "absolute locations" that are sorted by inclusion order (roughly represents a location in a raw file with all #include resolved). - The absolute location can be used in the pragma warning timeline * Added preprocessor #pragma warning tests. - Fixed #pragma warning (push / pop) SourceLoc - Fixed unused directiveLoc in #pragma warning parsing * #pragma warning: Added some comments and fixed some typos * Cleaned #pragma warning preprocessor implementation. --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/preprocessor/pragma-warning')
-rw-r--r--tests/preprocessor/pragma-warning/default-1.slang14
-rw-r--r--tests/preprocessor/pragma-warning/defined-1.slang16
-rw-r--r--tests/preprocessor/pragma-warning/defined-2.slang18
-rw-r--r--tests/preprocessor/pragma-warning/disable-1.slang14
-rw-r--r--tests/preprocessor/pragma-warning/error-1.slang14
-rw-r--r--tests/preprocessor/pragma-warning/helper-1.slang1
-rw-r--r--tests/preprocessor/pragma-warning/helper-2.slang3
-rw-r--r--tests/preprocessor/pragma-warning/multi-specifiers-1.slang14
-rw-r--r--tests/preprocessor/pragma-warning/multi-specifiers-2.slang18
-rw-r--r--tests/preprocessor/pragma-warning/once-1.slang16
-rw-r--r--tests/preprocessor/pragma-warning/once-2.slang25
-rw-r--r--tests/preprocessor/pragma-warning/pop-empty.slang7
-rw-r--r--tests/preprocessor/pragma-warning/push-pop-1.slang14
-rw-r--r--tests/preprocessor/pragma-warning/push-pop-2.slang15
-rw-r--r--tests/preprocessor/pragma-warning/push-pop-once.slang17
-rw-r--r--tests/preprocessor/pragma-warning/pushed-not-popped.slang7
-rw-r--r--tests/preprocessor/pragma-warning/suppress-1.slang14
-rw-r--r--tests/preprocessor/pragma-warning/with-includes-1.slang14
-rw-r--r--tests/preprocessor/pragma-warning/with-includes-2.slang14
-rw-r--r--tests/preprocessor/pragma-warning/wrong-specifier.slang7
20 files changed, 262 insertions, 0 deletions
diff --git a/tests/preprocessor/pragma-warning/default-1.slang b/tests/preprocessor/pragma-warning/default-1.slang
new file mode 100644
index 000000000..46046ce69
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/default-1.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+#pragma warning (default : 30081)
+ // CHECK: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Simple test of #pragma warning (default) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/defined-1.slang b/tests/preprocessor/pragma-warning/defined-1.slang
new file mode 100644
index 000000000..0827aa1f3
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/defined-1.slang
@@ -0,0 +1,16 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+#define SPECIFIER error
+#define IDs 30081 12 23 45
+
+void f()
+{
+ int i;
+#pragma warning (SPECIFIER : IDs)
+ // CHECK: ([[# @LINE+1]]): error 30081:
+ i = GetValue();
+}
+
+// Test that #pragma warning works with #defined specifiers and IDs \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/defined-2.slang b/tests/preprocessor/pragma-warning/defined-2.slang
new file mode 100644
index 000000000..7cde40a5a
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/defined-2.slang
@@ -0,0 +1,18 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+#define SPECIFIER disable
+#define IDs 30081
+
+void f()
+{
+ int i;
+#pragma warning (error : 30081)
+ // CHECK: ([[# @LINE+1]]): error 30081:
+ i = GetValue();
+#pragma warning (SPECIFIER : IDs)
+}
+
+// Test that #pragma warning with #defined specifiers and IDs uses the correct SourceLoc
+// (Use the macro invocation's SourceLoc, not the macro definition's SourceLoc) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/disable-1.slang b/tests/preprocessor/pragma-warning/disable-1.slang
new file mode 100644
index 000000000..c93845818
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/disable-1.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+#pragma warning (disable : 30081)
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Simple test of #pragma warning (disable) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/error-1.slang b/tests/preprocessor/pragma-warning/error-1.slang
new file mode 100644
index 000000000..a80e2bd89
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/error-1.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+#pragma warning (error : 30081)
+ // CHECK: ([[# @LINE+1]]): error 30081:
+ i = GetValue();
+}
+
+// Simple test of #pragma warning (error) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/helper-1.slang b/tests/preprocessor/pragma-warning/helper-1.slang
new file mode 100644
index 000000000..f5555e4f5
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/helper-1.slang
@@ -0,0 +1 @@
+#pragma warning (disable : 30081) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/helper-2.slang b/tests/preprocessor/pragma-warning/helper-2.slang
new file mode 100644
index 000000000..2d448a6d2
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/helper-2.slang
@@ -0,0 +1,3 @@
+#pragma warning (push)
+#pragma warning (disable : 30081)
+#pragma warning (pop) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/multi-specifiers-1.slang b/tests/preprocessor/pragma-warning/multi-specifiers-1.slang
new file mode 100644
index 000000000..7c299ed13
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/multi-specifiers-1.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+#pragma warning (disable : 30081 ; error : 30081)
+ // CHECK: ([[# @LINE+1]]): error 30081:
+ i = GetValue();
+}
+
+// Test that the last specifier is applied \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/multi-specifiers-2.slang b/tests/preprocessor/pragma-warning/multi-specifiers-2.slang
new file mode 100644
index 000000000..f4960bf75
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/multi-specifiers-2.slang
@@ -0,0 +1,18 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+#pragma warning (disable : 30081 15205)
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+ // CHECK-NOT: ([[# @LINE+1]]): warning 15205:
+#if MY_MACRO
+
+#endif
+}
+
+// Test a warning specifier on two ids \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/once-1.slang b/tests/preprocessor/pragma-warning/once-1.slang
new file mode 100644
index 000000000..e8ac29d3e
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/once-1.slang
@@ -0,0 +1,16 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+#pragma warning (once : 30081)
+ // CHECK: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Simple test of #pragma warning (once) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/once-2.slang b/tests/preprocessor/pragma-warning/once-2.slang
new file mode 100644
index 000000000..423991407
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/once-2.slang
@@ -0,0 +1,25 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+#pragma warning (once : 30081)
+ // CHECK: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+#pragma warning (once : 30081)
+ // CHECK: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Test that #pragma warning (once) are emitted once per segment \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/pop-empty.slang b/tests/preprocessor/pragma-warning/pop-empty.slang
new file mode 100644
index 000000000..bc1ec1d48
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/pop-empty.slang
@@ -0,0 +1,7 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+// CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+#pragma warning (pop)
+
+// Test that #pragma warning (pop) emits a warning when the stack is empty \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/push-pop-1.slang b/tests/preprocessor/pragma-warning/push-pop-1.slang
new file mode 100644
index 000000000..a6265dc9f
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/push-pop-1.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+#pragma warning (push)
+#pragma warning (error : 30081)
+int64_t GetValue();
+#pragma warning (pop)
+void f()
+{
+ int i;
+ // CHECK: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Test that #pragma warning (push) and (pop) work as expected \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/push-pop-2.slang b/tests/preprocessor/pragma-warning/push-pop-2.slang
new file mode 100644
index 000000000..0ebf5a85d
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/push-pop-2.slang
@@ -0,0 +1,15 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+#pragma warning (error : 30081)
+#pragma warning (push)
+#pragma warning (disable : 30081)
+int64_t GetValue();
+#pragma warning (pop)
+void f()
+{
+ int i;
+ // CHECK: ([[# @LINE+1]]): error 30081:
+ i = GetValue();
+}
+
+// Test that #pragma warning (push) and (pop) work as expected \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/push-pop-once.slang b/tests/preprocessor/pragma-warning/push-pop-once.slang
new file mode 100644
index 000000000..1521840a8
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/push-pop-once.slang
@@ -0,0 +1,17 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+int64_t GetValue();
+void f()
+{
+ int i;
+#pragma warning (once : 30081)
+ // CHECK: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+#pragma warning (push)
+#pragma warning (once : 30081)
+#pragma warning (pop)
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Test that #pragma warning (push) and (pop) with (once) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/pushed-not-popped.slang b/tests/preprocessor/pragma-warning/pushed-not-popped.slang
new file mode 100644
index 000000000..0bcccd53e
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/pushed-not-popped.slang
@@ -0,0 +1,7 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+// CHECK: ([[# @LINE+1]]): warning 15612:
+#pragma warning (push)
+
+// Test that #pragma warning (push) emits a warning when the stack is not empty at the end \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/suppress-1.slang b/tests/preprocessor/pragma-warning/suppress-1.slang
new file mode 100644
index 000000000..bafe08b73
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/suppress-1.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+ // CHECK-NOT: ([[# @LINE+2]]): warning 30081:
+#pragma warning (suppress : 30081)
+ i = GetValue();
+}
+
+// Simple test of #pragma warning (suppress) \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/with-includes-1.slang b/tests/preprocessor/pragma-warning/with-includes-1.slang
new file mode 100644
index 000000000..397ef8487
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/with-includes-1.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+#include "helper-1.slang"
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+ // CHECK-NOT: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Test that the #pragma warning (disable) in helper-1.slang disables the warning on line 10 \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/with-includes-2.slang b/tests/preprocessor/pragma-warning/with-includes-2.slang
new file mode 100644
index 000000000..13e34520f
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/with-includes-2.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+#include "helper-2.slang"
+
+int64_t GetValue();
+
+void f()
+{
+ int i;
+ // CHECK: ([[# @LINE+1]]): warning 30081:
+ i = GetValue();
+}
+
+// Test that the #pragma warning (push / pop) englobing helper-2.slang are working \ No newline at end of file
diff --git a/tests/preprocessor/pragma-warning/wrong-specifier.slang b/tests/preprocessor/pragma-warning/wrong-specifier.slang
new file mode 100644
index 000000000..8962d4b27
--- /dev/null
+++ b/tests/preprocessor/pragma-warning/wrong-specifier.slang
@@ -0,0 +1,7 @@
+//TEST:SIMPLE(filecheck=CHECK):
+// #ifdef support
+
+// CHECK: ([[# @LINE+1]]): warning 15613:
+#pragma warning (diasble : 30081)
+
+// Test that #pragma warning emits a warning if the specifier ins't correct \ No newline at end of file