llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

track constraints between symbolics

Open llvmbot opened this issue 18 years ago • 4 comments

Bugzilla Link 2834
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @tkremenek

Extended Description

I get a null pointer dereference warning when I try to analyze following code:

void do_stupid_things(char* a, char* b)
{
	if (a != b) {
		if (a != NULL || b == NULL) {
			a[0] = '\0';
		}
	}
}

It should be the same as

void do_stupid_things(char* a, char* b)
{
	if (a != NULL && b == NULL) {
		a[0] = '\0';
	}
}

Which will not produce any warnings

llvmbot avatar Sep 28 '08 12:09 llvmbot

Excellent test case. The issue has to do with not tracking symbolic relationships between 'a' and 'b'; this is something that we need to do, but I probably won't be able to get to it in the immediate short term.

tkremenek avatar Sep 28 '08 19:09 tkremenek

assigned to @tkremenek

llvmbot avatar Sep 28 '08 12:09 llvmbot

Bisected: the tested witness changes behavior starting with https://github.com/llvm/llvm-project/commit/e63b488f2755f91e8147fd678ed525cf6ba007cc.

This comparison analyzes the supplied C example with --analyze -DNULL=0.

Godbolt: https://godbolt.org/z/rdzjhnnY4

  • Clang 11.0.1: Reports a null pointer dereference at a[0]
  • Clang 12.0.0: No longer reports the null pointer dereference at a[0]
  • Clang (trunk): Produces no null pointer dereference warning

This is only an observed change in behavior. I have not checked whether this commit addresses the cause of this report or only stops it from reproducing; whether that resolves the issue is up to the maintainers.

Prepared with assistance from Codex.

hongtaihu avatar Nov 02 '26 07:11 hongtaihu

Fixed by e63b488f2755f91e8147fd678ed525cf6ba007cc in clang-12

steakhal avatar Nov 04 '26 18:11 steakhal