On Sat, 16 Aug 2008, Frank Wallingford wrote:

>> Yes, and that is exactly my point.  The compiler already analyzes the
>> logic, and generates the msg if I have a potential problem.
>
> The compiler doesn't analyze the logic as well as you think it does. For
> example, there are no warnings here with gcc 4.1.2 using -Wuninitialized
> -O:
>
>  int foo(int y)
>  {
>    int x;
>    if (y == 1) x = 2;
>    if (y == 2) return x;
>    return 0;
>  }
>
> There are tools that can analyze programs statically, but only the
> commercial ones provide what you want, as far as I know.
>
>  http://spinroot.com/static/
>
> If you are an IBMer I know of an IBM internal tool that may help.
>
> Also, using gcc 4.1.2, I get the line number of the use, not of the
> declaration. Which compiler are you using?
>
>> First, I want to know if I have a potential problem.
>
> This is a very hard problem, especially if your generated code is
> many-thousands-of-lines in a single function with gotos. Even worse if
> they are backwards gotos.
>
>> I am slowly coming around to the point of view that maybe the dataflow
>> analysis is not so hard.  The hardest part of such a program is to have
>> a correct parser for the input language.
>
> Just write something for gcc and you're all set as far as parsing goes.
> Good luck :) In fact, the llvm framework would probably allow you to do
> what you wanted, but you may have to write code for it:
>
>  http://clang.llvm.org/StaticAnalysis.html
>
> It has a gcc front-end, so parsing isn't an issue.
>
>> In a way, working with the output of the program generator is no different
>> than working with someone else's grubby program that gets the used before
>> defined msg.
>
> I've never seen a human write a routine so long or complicated that I
> couldn't find an uninitialized use of a variable by inspection. I stand by
> my assertion that if that's not possible in a reasonable amount of time,
> then the code needs re-structuring.
>
>> Someone else says to me, can you help me out? I have 40,000 lines of 30
>> programs, and I'm getting this msg 150 times for 150 variables.  How do I
>> fix it?  I mean really fix it, not just make the msg go away.
>>
>> In that case, I have to assume that I don't have control over how the
>> program was written, I just have to fix the problem by finding the stmts
>> that may cause errors, and, hopefully only those that may cause errors,
>> and exactly which ones.
>>
>> The script should work for any C++ program, whether it has gotos or not.
>
> If someone came to me with such a proposition I would laugh at them,
> unless they paid me a lot of money. If the code is that terrible, there's
> a significant risk to making any change at all. The code is just too
> fragile.
>
> If you are generating the code that you are concerned about, then you can
> just add logic to your generator to ensure that all uses of a generated
> variable follow some initialization. Surely if you are generating the uses
> and initializations than you have enough information to do the analysis
> you have in mind at that point, no?
>
> -Frank
>
> ----------------------------------
Ahh, the light dawns..

If I change your example without the warning msg slightly, i.e.

   int foo(int y)
   {
     int x;
//  if (y == 1) x = 2;
     if (x == 5) return(9);
     if (y == 2) return x;
     return 0;
   }

Then I do indeed get the correct line number of the uninitialized use.
Apparently whenever it sees a POTENTIAL set, it thinks it is real, and
doesn't bother to check after that.

That is not at all what I wanted. The compiler does not identify
all potential problems, only things that it knows for sure are problems.
That seems pretty worthless! Why isn't there an option that flags ALL
potential problems?

I can imagine that the reason there isn't is because, as you say, it is a 
harder problem, and the gcc writers don't want to get involved.
That is what the microsoft C++ team said in a faq page when someone asked 
why their compiler didn't find all of the interesting information.

Of course, since I got the msg, in this case I know I have a problem, but 
I would have liked more.

So, it looks like I have to deal with the fact that variables are
initialized or uninitialized in the generator, and I cannot
rely on the compiler for accurate information.

The next version of the generator will be based on unification, and
derive the program from a set of predicate clauses.

Lex
_______________________________________________
Mid-Hudson Valley Linux Users Group                  http://mhvlug.org          
   
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug                           
Upcoming Meetings (6pm - 8pm)                         MHVLS Auditorium          
        
  Jun 4 - Sqeak! and eToys
  Jul 2 - KVM (Tenative)
  Aug 6 - Zenos
  Sep 3 - TBD

Reply via email to