summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2188.c
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/regression/tests/bug-2188.c
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/regression/tests/bug-2188.c')
-rwxr-xr-xsupport/regression/tests/bug-2188.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/support/regression/tests/bug-2188.c b/support/regression/tests/bug-2188.c
new file mode 100755
index 0000000..4d77c55
--- /dev/null
+++ b/support/regression/tests/bug-2188.c
@@ -0,0 +1,58 @@
+/* bug 2188
+ Function miscompiled when inline selected
+ temporal variable for function return value
+ is forced to int type even that type is already
+ resolved because variable name is hidden in
+ the internal scope of inline function.
+*/
+
+#include <testfwk.h>
+#include <stdint.h>
+
+volatile int32_t glob_var32_a = 0x12345678;
+volatile int32_t glob_var32_b = 0x0abcdef0;
+
+inline
+int32_t inline_fnc(char sel)
+{
+ return sel? glob_var32_b: glob_var32_a;
+}
+
+int32_t notinlined_fnc(int32_t val)
+{
+ return val;
+}
+
+inline
+int32_t *inline_ptr_fnc(char sel)
+{
+ return sel? &glob_var32_b: &glob_var32_a;
+}
+
+int32_t notinlined_ptr_fnc(int32_t *pval)
+{
+ return *pval;
+}
+
+void
+testBug (void)
+{
+#ifndef __SDCC_pdk14 // Lack of memory
+ int32_t var32 = notinlined_fnc(inline_fnc(0));
+ ASSERT(var32 == glob_var32_a);
+ var32 = notinlined_fnc(inline_fnc(1));
+ ASSERT(var32 == glob_var32_b);
+
+ var32 = notinlined_ptr_fnc(inline_ptr_fnc(0));
+ ASSERT(var32 == glob_var32_a);
+ var32 = notinlined_ptr_fnc(inline_ptr_fnc(1));
+ ASSERT(var32 == glob_var32_b);
+#endif
+}
+
+extern inline
+int32_t inline_fnc(char sel);
+
+extern inline
+int32_t *inline_ptr_fnc(char sel);
+