llvm / llvm/llvm-project

[Analyzer] anomalous error message

Open
#203,700 18 comments 0 reactions 0 assignees View on GitHub
clang-tidy enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I am using clang-tidy (LLVM version 21.0.0git) on Windows 10 Pro.

I recently ran it on a new project, and got this error:

```
D:/SourceCode/Git/binclock_redux/config.cpp:90:8: note: Assuming ‘result’ is equal to 0
90 | if (result != 0)
| ^~~~~~~~~~~
D:/SourceCode/Git/binclock_redux/config.cpp:90:4: note: Taking false branch
90 | if (result != 0)
| ^
```

yet this is the code at line 90:

```c++
LRESULT result = derive_filename_from_exec(ini_name, (TCHAR ) _T(“.ini”)) ;
if (result != 0) {
return result;
}
```

and that function is definitely capable of returning either 0 or non-0 results…
Why do I get these reports (there are several of them) ??

==================================================
Later note:
Actually, these spurious warnings are apparently caused by another (valid) warning:

D:/SourceCode/Git/binclock_redux/config.cpp:140:11: note: Opened stream never closed. Potential resource leak
140 | return 0;

Once I added
fclose(fd);
to the end of this function, all of the other 12 warnings went away…

still… were these other warnings desirable, for some reason??

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the clang-tidy diagnostics from config.cpp around line 90, then inspect the stream-handling path around line 140 and compare results with and without fclose(fd). Determine whether the additional path-sensitive notes are expected after the resource-leak warning; done means the behavior is explained and any necessary analyzer change is covered by an appropriate regression case.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.