tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] patch for illegal cast error check


From: Ben Hinkle
Subject: [Tinycc-devel] patch for illegal cast error check
Date: Sun, 9 Oct 2005 21:04:30 -0400

From what I can tell tcc.0.9.23 doesn't generate an error on an illegal cast with a struct. For example

  struct Foo{int test;};
  void foo(int x){}
  int main() {
    struct Foo a;
    int b = (int)a; // should fail
    foo(a); // also should fail
    return 0;
  }
 
The patch to gen_cast:
 
*** tcc.c       Sun Oct  9 20:52:14 2005
--- tccnew.c    Sun Oct  9 20:59:08 2005
*************** static void gen_cast(CType *type)
*** 5762,5767 ****
--- 5762,5775 ----
      sbt = vtop->type.t & (VT_BTYPE | VT_UNSIGNED);
 
      if (sbt != dbt && !nocode_wanted) {
+         // make sure types aren't structs
+         if ((sbt & VT_STRUCT) || (dbt & VT_STRUCT)) {
+           char buf1[256], buf2[256];
+           type_to_str(buf1, sizeof(buf1), &vtop->type, NULL);
+           type_to_str(buf2, sizeof(buf2), type, NULL);
+           error("cannot cast '%s' to '%s'", buf1, buf2);
+         }
+
          sf = is_float(sbt);
          df = is_float(dbt);
 
 

reply via email to

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