diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-03-31 13:11:49 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-31 13:11:49 -0400 |
| commit | 5fde038b1a6b3c8b335cd5b380c3ee8d15403052 (patch) | |
| tree | 27975331c960edc405a5294031fd6a4a79eff964 /tests | |
| parent | 5fefb120e0c2469563e937f4ee39b391d7678cdf (diff) | |
Support for __LINE__ and __FILE__ in preprocessor (#1772)
* #include an absolute path didn't work - because paths were taken to always be relative.
* First pass support for __LINE__ and __FILE__.
* Test include handling with __FILE__
Fix diagnostic compare when input is empty.
* Fix some issues in preprocessor handling of special macros like __LINE__
Add a more complex test.
* Use CONCAT2 in tests, because preprocessor doesn't quite get parameter expansion correct.
* Make __FILE__ and __LINE__ behave more like Clang/Gcc.
* A test for preprocessor bug.
* Fix __LINE__ and __FILE__ in macro expansion, should be initiating location.
* Fix some comments.
* Small tidy up around builtin macros.
* Small improvements for macro type names.
Escape found paths.
Diffstat (limited to 'tests')
15 files changed, 156 insertions, 0 deletions
diff --git a/tests/preprocessor/include/special-macro-include.h b/tests/preprocessor/include/special-macro-include.h new file mode 100644 index 000000000..f2aa20951 --- /dev/null +++ b/tests/preprocessor/include/special-macro-include.h @@ -0,0 +1,5 @@ +// special-macro-include.h + +// Used by the `special-macro-include.slang` test + +__FILE__ __LINE__
\ No newline at end of file diff --git a/tests/preprocessor/paste-non-expansion.slang b/tests/preprocessor/paste-non-expansion.slang new file mode 100644 index 000000000..8270db676 --- /dev/null +++ b/tests/preprocessor/paste-non-expansion.slang @@ -0,0 +1,16 @@ +//DIAGNOSTIC_TEST:SIMPLE:-E + +// NOTE! This test should *fail*, if preprocessor is working correctly! + +// This demonstrates the existance of a bug in Slang preprocessor macro expansion. Could be due to incorrect paste handling +// or perhaps the rules around parameter expansion. + +#define CONCAT2(x, y) x ## y +#define CONCAT(x, y) CONCAT2(x, y) + +#define SOMETHING someThing + +// Should be someThingElse +CONCAT(SOMETHING, Else) +// Should be SOMETHINGAnother, but Slang expands to produce someThingAnother +CONCAT2(SOMETHING, Another)
\ No newline at end of file diff --git a/tests/preprocessor/paste-non-expansion.slang.expected b/tests/preprocessor/paste-non-expansion.slang.expected new file mode 100644 index 000000000..2fbb7bad3 --- /dev/null +++ b/tests/preprocessor/paste-non-expansion.slang.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +} +standard output = { +someThingElse someThingAnother +} diff --git a/tests/preprocessor/special-macro-complex.slang b/tests/preprocessor/special-macro-complex.slang new file mode 100644 index 000000000..a2ea962e1 --- /dev/null +++ b/tests/preprocessor/special-macro-complex.slang @@ -0,0 +1,37 @@ +//DIAGNOSTIC_TEST:SIMPLE:-E + +// Testing of handling of __LINE__ in macros +// Pasting, and some other aspects. + + +// Lets try some macro pasting. NOTE strictly speaking we need CONCAT2 (as tested on other compilers, but Slang does not indicating a preprocessor bug!) +#define CONCAT2(x, y) x ## y +#define CONCAT(x, y) CONCAT2(x, y) + +CONCAT(Thing, __LINE__) + +// Lets see if works okay in conditionals + +#if __LINE__ == 15 +Yeppers +#else +Nopers +#endif + +// Lets try a paste in a conditional +#if CONCAT(__LINE__, __LINE__) == 2222 +PasteConditional +#endif + +// Lets check that we pick up the nominal line +#line 10 +__LINE__ + +// Reset the line numbering +#line default + +// __LINE__ number will be for the macro invocation, not the expansion + +#define SOMEMACRO __LINE__ + +SOMEMACRO
\ No newline at end of file diff --git a/tests/preprocessor/special-macro-complex.slang.expected b/tests/preprocessor/special-macro-complex.slang.expected new file mode 100644 index 000000000..542fd320d --- /dev/null +++ b/tests/preprocessor/special-macro-complex.slang.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +} +standard output = { +Thing11 Yeppers PasteConditional 10 37 +} diff --git a/tests/preprocessor/special-macro-include.slang b/tests/preprocessor/special-macro-include.slang new file mode 100644 index 000000000..79aa8b566 --- /dev/null +++ b/tests/preprocessor/special-macro-include.slang @@ -0,0 +1,4 @@ +//DIAGNOSTIC_TEST:SIMPLE:-E + +#include "./include/special-macro-include.h" +#include "include/special-macro-include.h"
\ No newline at end of file diff --git a/tests/preprocessor/special-macro-include.slang.expected b/tests/preprocessor/special-macro-include.slang.expected new file mode 100644 index 000000000..f95c8303a --- /dev/null +++ b/tests/preprocessor/special-macro-include.slang.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +} +standard output = { +"tests/preprocessor/include/special-macro-include.h" 5 "tests/preprocessor/include/special-macro-include.h" 5 +} diff --git a/tests/preprocessor/special-macro-multi-line.slang b/tests/preprocessor/special-macro-multi-line.slang new file mode 100644 index 000000000..b8d12d601 --- /dev/null +++ b/tests/preprocessor/special-macro-multi-line.slang @@ -0,0 +1,12 @@ +//DIAGNOSTIC_TEST:SIMPLE:-E + +// Output here varies by compiler. Gcc makes the line the one with M. Clang makes it the end bracket. + +#define M(ARG) __LINE__ + + +int x = M +( +ignored +) +; diff --git a/tests/preprocessor/special-macro-multi-line.slang.expected b/tests/preprocessor/special-macro-multi-line.slang.expected new file mode 100644 index 000000000..984ce94f5 --- /dev/null +++ b/tests/preprocessor/special-macro-multi-line.slang.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +} +standard output = { +int x = 8 ; +} diff --git a/tests/preprocessor/special-macro-redefine-function.slang b/tests/preprocessor/special-macro-redefine-function.slang new file mode 100644 index 000000000..cca38f39f --- /dev/null +++ b/tests/preprocessor/special-macro-redefine-function.slang @@ -0,0 +1,14 @@ +//DIAGNOSTIC_TEST:SIMPLE:-E + +// +// Check replacing __FILE__ +// + +#define __FILE__(x) "Is" x + +__FILE__("Anybody") +__FILE__(There) + +#undef __FILE__ + +__FILE__
\ No newline at end of file diff --git a/tests/preprocessor/special-macro-redefine-function.slang.expected b/tests/preprocessor/special-macro-redefine-function.slang.expected new file mode 100644 index 000000000..923335509 --- /dev/null +++ b/tests/preprocessor/special-macro-redefine-function.slang.expected @@ -0,0 +1,9 @@ +result code = 0 +standard error = { +tests/preprocessor/special-macro-redefine-function.slang(7): warning 15404: Redefinition of builtin macro '__FILE__' +#define __FILE__(x) "Is" x + ^~~~~~~~ +} +standard output = { +"Is" "Anybody" "Is" There __FILE__ +} diff --git a/tests/preprocessor/special-macro-redefine-object.slang b/tests/preprocessor/special-macro-redefine-object.slang new file mode 100644 index 000000000..531d56ae7 --- /dev/null +++ b/tests/preprocessor/special-macro-redefine-object.slang @@ -0,0 +1,13 @@ +//DIAGNOSTIC_TEST:SIMPLE:-E + +// +// Check replacing __LINE__ +// + +#define __LINE__ "Hello" + +__LINE__ + +#undef __LINE__ + +__LINE__ diff --git a/tests/preprocessor/special-macro-redefine-object.slang.expected b/tests/preprocessor/special-macro-redefine-object.slang.expected new file mode 100644 index 000000000..ed5fbb16e --- /dev/null +++ b/tests/preprocessor/special-macro-redefine-object.slang.expected @@ -0,0 +1,9 @@ +result code = 0 +standard error = { +tests/preprocessor/special-macro-redefine-object.slang(7): warning 15404: Redefinition of builtin macro '__LINE__' +#define __LINE__ "Hello" + ^~~~~~~~ +} +standard output = { +"Hello" __LINE__ +} diff --git a/tests/preprocessor/special-macro-simple.slang b/tests/preprocessor/special-macro-simple.slang new file mode 100644 index 000000000..e6e823475 --- /dev/null +++ b/tests/preprocessor/special-macro-simple.slang @@ -0,0 +1,7 @@ +//DIAGNOSTIC_TEST:SIMPLE:-E + +//__LINE__ and __FILE__ support + +__LINE__ + +__FILE__ diff --git a/tests/preprocessor/special-macro-simple.slang.expected b/tests/preprocessor/special-macro-simple.slang.expected new file mode 100644 index 000000000..6d8b5212d --- /dev/null +++ b/tests/preprocessor/special-macro-simple.slang.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +} +standard output = { +5 "tests/preprocessor/special-macro-simple.slang" +} |
