llvm / llvm/llvm-project

[Clang] Control-flow analysis around expansion statements could be better

Open
#211,939 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

c++26 clang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Concretely, consider (https://godbolt.org/z/e75Kx1WMr)

int f() {
    template for (int x : {1}) {
        return 4;
    }
}

which currently results in a warning

<source>:5:1: warning: non-void function does not return a value [-Wreturn-type]
    5 | }
      | ^

despite the fact that we do in fact always return here, as the expansion statement effectively expands to

int f() {
    {
        {
            int x = 1;
            return 4;
        }
    }
}

which we don’t warn about. Presumably, the fix is that we should probably be walking the CXXExpansionStmtInstantiation of an expansion statement rather than the pattern.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Godbolt example linked in the issue and trace Clang's control-flow analysis for the expansion statement. Compare how analysis treats the CXXExpansionStmtInstantiation with how it treats the pattern. Done means the shown function is recognized as always returning and no longer produces the -Wreturn-type warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.