Analyzer: Bogus FixedAddressDereference warning for non-constant pointer
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Hi,
In the attached, greatly simplified (and pointless-ified), postgres code, FixedAddressDereference triggers a bogus warning.
[policy_edit.c](https://github.com/user-attachments/files/27724522/policy_edit.c)
```
$ clang-23 --analyze -Xclang -analyzer-checker=optin.core.FixedAddressDereference --analyzer-output text -xc policy_edit.c
policy_edit.c:21:10: warning: Array access (via field 'data') results in a dereference of a fixed address
[optin.core.FixedAddressDereference]
21 | return tup->data[narg];
| ^
policy_edit.c:35:6: note: Assuming 'polcmd' is equal to 17
35 | if (polcmd != 17 && stmt->with_check != 0)
| ^~~~~~~~~~~~
policy_edit.c:35:19: note: Left side of '&&' is false
35 | if (polcmd != 17 && stmt->with_check != 0)
| ^
policy_edit.c:41:17: note: Passing pointer value (Tuple *)17 via 1st parameter 'tup'
41 | return get_att(policy_tuple, argbyval, 1);
| ^~~~~~~~~~~~
policy_edit.c:41:9: note: Calling 'get_att'
41 | return get_att(policy_tuple, argbyval, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
policy_edit.c:18:6: note: Assuming the condition is false
18 | if (argbyval[narg] == 0)
| ^~~~~~~~~~~~~~~~~~~
policy_edit.c:18:2: note: Taking false branch
18 | if (argbyval[narg] == 0)
| ^
policy_edit.c:21:10: note: Array access (via field 'data') results in a dereference of a fixed address
21 | return tup->data[narg];
| ^ ~~~~
1 warning generated.
```
Note how, after comparing polcmd with 17, the analyzer thinks the tuple arguments to get_att is 17 as well. Which makes no sense, afaict.
Greetings,
Andres
Contributor guide
Research direction
Start by running the clang-23 analyzer command from the issue against the attached policy_edit.c and reproduce the optin.core.FixedAddressDereference warning. Then trace the checker’s handling of the comparison and pointer argument; done means the non-constant pointer no longer produces this bogus fixed-address warning while genuine fixed-address dereferences remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100