bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] Make casts lose top-level qualifiers


From: Ekaitz Zarraga
Subject: [PATCH 1/2] Make casts lose top-level qualifiers
Date: Tue, 30 Jan 2024 00:25:53 +0100

TODO: also make them lose lvalue status
---
 tccgen.c                  |  1 +
 tests/tests2/94_generic.c | 81 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 tests/tests2/94_generic.c

diff --git a/tccgen.c b/tccgen.c
index efd53869..cbdaadc2 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -2517,6 +2517,7 @@ static void gen_cast(CType *type)
                   | (lvalue_type(type->ref->type.t) & VT_LVAL_TYPE);
     }
     vtop->type = *type;
+    vtop->type.t &= ~ ( VT_CONSTANT | VT_VOLATILE | VT_ARRAY );
 }
 
 /* return type size as known at compile time. Put alignment at 'a' */
diff --git a/tests/tests2/94_generic.c b/tests/tests2/94_generic.c
new file mode 100644
index 00000000..78ca9129
--- /dev/null
+++ b/tests/tests2/94_generic.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+
+const int a = 0;
+
+struct a {
+       int a;
+};
+
+struct b {
+       int a;
+};
+
+int a_f()
+{
+       return 20;
+}
+
+int b_f()
+{
+       return 10;
+}
+
+typedef int (*fptr)(int);
+int foo(int i)
+{
+  return i;
+}
+
+typedef int int_type1;
+
+#define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123);
+
+int main()
+{
+       int i = 0;
+       signed long int l = 2;
+       struct b titi;
+       const int * const ptr;
+       const char *ti;
+       int_type1 i2;
+
+       i = _Generic(a, int: a_f, const int: b_f)();
+       printf("%d\n", i);
+       i = _Generic(a, int: a_f() / 2, const int: b_f() / 2);
+       printf("%d\n", i);
+       i = _Generic(ptr, int *:1, int * const:2, default:20);
+       printf("%d\n", i);
+       i = gen_sw(a);
+       printf("%d\n", i);
+       i = _Generic(titi, struct a:1, struct b:2, default:20);
+       printf("%d\n", i);
+       i = _Generic(i2, char: 1, int : 0);
+       printf("%d\n", i);
+       i = _Generic(a, char:1, int[4]:2, default:5);
+       printf("%d\n", i);
+       i = _Generic(17, int :1, int **:2);
+       printf("%d\n", i);
+       i = _Generic(17L, int :1, long :2, long long : 3);
+       printf("%d\n", i);
+       i = _Generic("17, io", char *: 3, const char *: 1);
+       printf("%d\n", i);
+       i = _Generic(ti, const unsigned char *:1, const char *:4, char *:3,
+                    const signed char *:2);
+       printf("%d\n", i);
+       printf("%s\n", _Generic(i + 2L, long: "long", int: "int",
+                               long long: "long long"));
+       i = _Generic(l, long: 1, int: 2);
+       printf("%d\n", i);
+       i = _Generic(foo, fptr: 3, int: 4);
+       printf("%d\n", i);
+
+       (void)_Generic((int(*)[2]){0}, int(*)[2]:0, int(*)[4]:0); //shouldn't 
match twice
+
+       //should accept ({ }) in the controlling expr of _Generic even in 
const_wanted contexts
+       struct { _Bool x_0: _Generic(({0;}),default:1); } my_x;
+
+       _Generic((__typeof((float const)((float const){42}))*){0}, float*: 0); 
//casts lose top-level qualifiers
+       int const x = 42; __typeof((__typeof(x))x) *xp = 0; (void)_Generic(xp, 
int*: 0); //casts lose top-level qualifiers
+
+       return 0;
+}
-- 
2.41.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]