[patch] Refactor the Used flag logic (and a small bug fix)

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Oct 23 09:48:20 PDT 2013


I am having second thoughts about this patch. IsUsed is a common
operation. We probably don't want to loop in it. We could loop in
setUsed to set every decl used, but we still have the problem of what
to do about UsedAttr.

In the end having the callers be careful might be the best, but
brittle, solution. I will see if I can fix the small bug without
introducing a loop in isUsed.

On 23 October 2013 12:10, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
> Hi Richard,
>
> This is mostly an implementation of your suggestion on how to handle
> the Used flag.
>
> At first I thought the best candidate for holding the flag was the
> first decl. Doing that would remove the need the propagate the flag to
> newer decls. The problem is that there are cases where we want to know
> if a particular decl has the UsedAttr, so we cannot just add a
> UsedAttr to the first decl.
>
> The next best candidate was the last decl. This requires merging the
> flag, but that is not too hard.
>
> Yet another option would be checking the first decl for the flag and
> the last one for the attribute. There is a link from the first to the
> last, so going from one to the other is fairly fast.
>
> The patch also
> * Fixes a small bug: We would consider func unused in
>
> static void func();
> void bar() { void func() __attribute__((used)); }
> static void func() {}
>
> * Removes the argument to setIsUsed. Given its meaning, it does'n make
> sense to clear the flag.
>
> * Removes the special case in MarkFunctionReferenced.
>
> Cheers,
> Rafael




More information about the cfe-commits mailing list