summary refs log tree commit diff stats
path: root/tinyc/tests/tests2/92_enum_bitfield.c
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-11-02 10:46:30 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-11-02 10:46:30 +0100
commit1eaeccc15d15d15d2f62ea1648f7dd64722dbd37 (patch)
treeb922cdabc780fa3a8837a6804d2df31793d9e2ca /tinyc/tests/tests2/92_enum_bitfield.c
parente9243a16167b24899d4fcf051f3252b3a5804811 (diff)
parentbd19b5f4d36bb40b4af93d7e15fdfa582e9fe3b7 (diff)
downloadNim-1eaeccc15d15d15d2f62ea1648f7dd64722dbd37.tar.gz
Merge branch 'devel' into araq
Diffstat (limited to 'tinyc/tests/tests2/92_enum_bitfield.c')
-rw-r--r--tinyc/tests/tests2/92_enum_bitfield.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/tinyc/tests/tests2/92_enum_bitfield.c b/tinyc/tests/tests2/92_enum_bitfield.c
new file mode 100644
index 000000000..bb6dc35d2
--- /dev/null
+++ b/tinyc/tests/tests2/92_enum_bitfield.c
@@ -0,0 +1,57 @@
+/* This checks if enums needing 8 bit but only having positive
+   values are correctly zero extended (instead of sign extended)
+   when stored into/loaded from a 8 bit bit-field of enum type (which
+   itself is implementation defined, so isn't necessarily supported by all
+   other compilers).  */
+enum tree_code {
+  SOME_CODE = 148, /* has bit 7 set, and hence all further enum values as well */
+  LAST_AND_UNUSED_TREE_CODE
+};
+typedef union tree_node *tree;
+struct tree_common
+{
+  union tree_node *chain;
+  union tree_node *type;
+  enum tree_code code : 8;
+  unsigned side_effects_flag : 1;
+};
+union tree_node
+{
+  struct tree_common common;
+ };
+enum c_tree_code {
+  C_DUMMY_TREE_CODE = LAST_AND_UNUSED_TREE_CODE,
+  STMT_EXPR,
+  LAST_C_TREE_CODE
+};
+enum cplus_tree_code {
+  CP_DUMMY_TREE_CODE = LAST_C_TREE_CODE,
+  AMBIG_CONV,
+  LAST_CPLUS_TREE_CODE
+};
+
+extern int printf(const char *, ...);
+int blah(){return 0;}
+
+int convert_like_real (tree convs)
+{
+  switch (((enum tree_code) (convs)->common.code))
+    {
+    case AMBIG_CONV: /* This has bit 7 set, which must not be the sign
+			bit in tree_common.code, i.e. the bitfield must
+			be somehow marked unsigned.  */
+      return blah();
+    default:
+      break;
+    };
+   printf("unsigned enum bit-fields broken\n");
+}
+
+int main()
+{
+  union tree_node convs;
+
+  convs.common.code = AMBIG_CONV;
+  convert_like_real (&convs);
+  return 0;
+}