[cfe-dev] -Wunreachable-code and templates

David Blaikie dblaikie at gmail.com
Fri Dec 2 00:14:58 PST 2011


> > Slightly related/minor tidyup - should the isType/ValueDependent
> > checks in tryEvaluate/tryEvaluateBool be removed (and possibly
> > replaced with assertions) as they don't seem to do anything - we
> > weren't visiting dependent contexts previously nor are we now.
>
> I'd be happy with that if we just had CFGBuilder abort up front the
> construction on raw (uninstantiated) templates.  This defensive code is
> there so that other clients of CFGBuilder (besides AnalysisBasedWarnings)
> don't get into trouble.

Before doing that tidyup I decided to have a go at the "simple" thing
- doing unreachable code on templates instead of their instantiations.
No doubt it's not the tidiest implementation (suppressing all the
other analysis based warnings when 'dependent' is true is a bit
intrusive/repetitive) but it seems to show the concept fairly well.

I don't think we'd discussed in detail what problems might arise from
this approach - certainly we know cases that we can't prove (such as a
dependent function call which may or may not be noreturn) but
non-dependent calls to noreturn functions, for example, seem to work
correctly (without regressing your test cases that cover the dependent
noreturn case).

Are there other cases I've missed where this approach could be problematic?

(I've also made some changes to the array-bounds tests here - an
indirect discovery while experimenting with this change: we emit
warnings that are contingent on reachability for every instantiation
even when the expression is not dependent. It'd be nice if we didn't
do that, but it's not too important I suppose - since the warning is
legitimate & it'll all versions will go away when it's fixed. The
minor advantage of warning on uninstantiated templates is probably
marginal (& perhaps debatable - it's not really reachable if the
template was never instantiated, but we're not doing interprocedural
analysis anyway - so a real (non-template) function has the same issue
anyway)).

Thoughts?
- David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unreachable_templates.diff
Type: text/x-diff
Size: 4502 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111202/9267e1d3/attachment.diff>


More information about the cfe-dev mailing list