compiler/libec; ide/debugger: Fixed sizeof((char *)"abc")
authorJerome St-Louis <jerome@ecere.com>
Wed, 7 May 2014 02:42:47 +0000 (22:42 -0400)
committerJerome St-Louis <jerome@ecere.com>
Wed, 7 May 2014 02:42:47 +0000 (22:42 -0400)
- The cast must be kept as this should evaluate to the size of a pointer

compiler/bootstrap/libec/bootstrap/pass15.c
compiler/libec/src/pass15.ec
ide/src/debugger/debugTools.ec

index decce6e..a2565fe 100644 (file)
@@ -11608,7 +11608,7 @@ if(exp->op.exp2)
 {
 struct Expression * e = exp->op.exp2;
 
-while(((e->type == 5 || e->type == 32 || e->type == 23) && e->list) || e->type == 11)
+while((e->type == 5 || e->type == 32 || e->type == 23) && e->list)
 {
 if(e->type == 5 || e->type == 32 || e->type == 23)
 {
@@ -11617,8 +11617,6 @@ e = (*((struct Statement *)(*e->compound->compound.statements).last)->expression
 else
 e = (*e->list).last;
 }
-else if(e->type == 11)
-e = e->cast.exp;
 }
 if(exp->op.op == 261 && e && e->expType)
 {
@@ -14149,6 +14147,23 @@ type1->refCount++;
 }
 if(exp->op.exp2->destType && exp->op.op != '=')
 exp->op.exp2->destType->count++;
+if(exp->op.op == SIZEOF)
+{
+struct Expression * e = exp->op.exp2;
+
+while((e->type == 5 || e->type == 32 || e->type == 23) && e->list)
+{
+if(e->type == 5 || e->type == 32 || e->type == 23)
+{
+if(e->type == 23)
+e = (*((struct Statement *)(*e->compound->compound.statements).last)->expressions).last;
+else
+e = (*e->list).last;
+}
+}
+if(e->type == 11 && e->cast.exp)
+e->cast.exp->needCast = 0x1;
+}
 ProcessExpressionType(exp->op.exp2);
 if(exp->op.exp2->destType && exp->op.op != '=')
 exp->op.exp2->destType->count--;
index dce3a10..36921c5 100644 (file)
@@ -5204,7 +5204,7 @@ void ComputeExpression(Expression exp)
          {
             Expression e = exp.op.exp2;
 
-            while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
+            while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
             {
                if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
                {
@@ -5213,8 +5213,6 @@ void ComputeExpression(Expression exp)
                   else
                      e = e.list->last;
                }
-               else if(e.type == castExp)
-                  e = e.cast.exp;
             }
             if(exp.op.op == TokenType::sizeOf && e && e.expType)
             {
@@ -8026,6 +8024,23 @@ void ProcessExpressionType(Expression exp)
                type1.refCount++;
             }
             if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
+            // Cannot lose the cast on a sizeof
+            if(exp.op.op == SIZEOF)
+            {
+               Expression e = exp.op.exp2;
+               while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
+               {
+                  if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
+                  {
+                     if(e.type == extensionCompoundExp)
+                        e = ((Statement)e.compound.compound.statements->last).expressions->last;
+                     else
+                        e = e.list->last;
+                  }
+               }
+               if(e.type == castExp && e.cast.exp)
+                  e.cast.exp.needCast = true;
+            }
             ProcessExpressionType(exp.op.exp2);
             if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
 
index 5a8260c..8693380 100644 (file)
@@ -400,7 +400,7 @@ void DebugComputeExpression(Expression exp)
          {
             Expression e = exp.op.exp2;
 
-            while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
+            while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
             {
                if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
                {
@@ -409,8 +409,6 @@ void DebugComputeExpression(Expression exp)
                   else
                      e = e.list->last;
                }
-               else if(e.type == castExp)
-                  e = e.cast.exp;
             }
             if(exp.op.op == TokenType::sizeOf && e && e.expType)
             {