I have a patch for this, but I'm not sure of the right way to offer it.
I'm attaching a file that I hope gets the point across. This enters all
the label names within a function body into alphaTable at the beginning
of processing a function definition.

Aside from fixing the problem I mentioned, this also has the benefit of
having CIL raise an error if there are duplicate label names, rather
than silently allowing them to go through.

Comments are welcome.

-Elnatan

On Mon, 2009-08-03 at 17:43 -0400, Elnatan Reisner wrote:
> CIL doesn't check the uniqueness of label names it uses when unfolding
> short-circuiting boolean operators. This can lead to problems if you
> already have a label named "_L" in your program. I've attached a tiny
> example that gets converted from a stupid but harmless program into a an
> infinite loop because of this.
> 
> I haven't yet managed to figure out all of the pieces involved in CIL's
> handling of labels, so if someone can suggest a fix for this, I'd
> appreciate it.
> 
> On a related (but not functionally problematic) note, is there a reason
> inserted gotos have their location marked as unknown, rather than as
> being the same as that of expression from which they originate? More
> specifically, Cabs2cil.compileCondExp creates gotos with the line
> 
>           (gotoChunk lab lu, consLabel lab sf !currentLoc false)
> 
> where "lu" is locUnknown. Is there a reason this shouldn't be "!
> currentLoc" instead?
> 
> -Elnatan
--- cabs2cil.ml~	2009-04-24 14:50:33.000000000 -0400
+++ cabs2cil.ml	2009-08-05 17:41:06.520503882 -0400
@@ -1089,6 +1089,17 @@
   with Not_found -> 
     l
 
+class gatherLabelsClass : V.cabsVisitor = object (self)
+  inherit V.nopCabsVisitor as super
+
+  method vstmt s = match s with
+  | A.LABEL (l,_,loc) ->
+      currentLoc := convLoc loc;
+      let newname, oldloc = newAlphaName false "label" l in
+      if newname <> l then E.s (error "Duplicate label name %s (previous use of this label is at %a)" l d_loc oldloc);
+      V.DoChildren
+  | _ -> V.DoChildren
+end
 
 (** ALLOCA ***)
 let allocaFun () = 
@@ -5522,6 +5533,10 @@
             (* Setup the environment. Add the formals to the locals. Maybe
             * they need alpha-conv  *)
             enterScope ();  (* Start the scope *)
+
+            (* Enter all the function's labels into the local scope *)
+            ignore (V.visitCabsBlock (new gatherLabelsClass) body);
+            currentLoc := funloc; (* gatherLabelsClass#vstmt changes currentLoc, so reset it here *)
             
             IH.clear varSizeArrays;
             
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to