[Prev][Next][Index]

A bug in getTrueType



Howdy,

I have found what I think is a pretty serious bug in the otherwise
excellently useful SgType::getTrueType() method contributed by Mauer
and included in the 1.7 distribution of Sage++.

This bug was not in his patch which he distributed for the 1.3.1 distribution
of Sage++, and in fact, once I found the bug, I fixed it using his original
code which I patched into my personal version of 1.3.1

Anyway, in the part of the getTrueType code which scans through pointer 
indirections until an equilibrium indirection of 0 is found, the variable
current is updated as the chain of baseTypes is examined.  Unfortunately,
the recursive call is incorrect, as it uses the variable "next," which
is never updated as the chain of baseTypes is scanned.

I believe that this recursive call is correct in the original patch
from Mauer.  In any case, it seems to work for my application.

Below I have included diffs.  Please check them out.

Also in the diff, you will find that I have added a rudimentary "unparse"
for types.  It is far from complete, but it helps me debug stuff, and is
pretty darned handy.  The way it includes the tag array is really lame,
but I wanted to get it up and running quickly.

Oh yeah, the diff includes some changes I made to getTrueType
which make it emit debugging code.  You can ignore them.  I thought that you
would want the diff to see where I made all of my changes.  The
important change to getTrueType is

2428c2445
<           return next->getTrueType(mask, follow_typedefs);
---
>           return current->baseType()->getTrueType(mask, follow_typedefs);



Thanks!
 
Michael
-------------------------------------------------------
mgolden@eecs.umich.edu
The human race has one really effective weapon, and that is laughter.
		-- Mark Twain

diff libSage++.C.old libSage++.C
25a26,29
> /* MLG */
> char *tag[610];
> /* GLM */
> 
2383c2387
< SgType *SgType::getTrueType (int mask, int follow_typedefs)
---
> SgType *SgType::getTrueType (int mask, int follow_typedefs, int debug)
2397a2402,2406
>           if (debug) {
>               printf ("POINTER -- current indirection: %d\n",
>                       current_indirection);
>           }
> 
2410a2420,2423
>                     if (debug) {
>                         printf ("\tPointer -- Adding %d\n",
>                                 isSgPointerType(next)->indirection());
>                     }
2416a2430,2433
>                     if (debug) {
>                         printf ("\tArray -- Adding %d\n",
>                                 isSgArrayType(next)->dimension());
>                     }
2428c2445
<           return next->getTrueType(mask, follow_typedefs);
---
>           return current->baseType()->getTrueType(mask, follow_typedefs);
2453a2471,2473
>           if (debug) {
>               printf ("ARRAY -- dimension : %d\n",the_array->dimension());
>           }
2469a2490,2519
> void SgType::unparsestdout()
> {
>     static int been_there = 0;
>     SgType *current = this;
> 
>     if (!been_there) {
> #include "tag.h"
>       been_there = 1;
>     }
> 
>     int variant = current->variant();
> 
>     printf ("%s:%d", tag[variant], variant);
> 
>     switch (variant) {
>     case T_POINTER:
>       printf("(%d)", ((SgPointerType *) current) -> indirection());
>       break;
> 
>     case T_ARRAY:
>       printf("[%d]", ((SgArrayType *) current) -> dimension());
>       break;
> 
>     }
> 
>     if (current->baseType()) {
>       printf (" -> ");
>       current->baseType()->unparsestdout();
>     }
> }