Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TySan] False positive related to structs in structs? #122517

Closed
seanm opened this issue Jan 10, 2025 · 7 comments
Closed

[TySan] False positive related to structs in structs? #122517

seanm opened this issue Jan 10, 2025 · 7 comments
Labels
compiler-rt:tysan Type sanitizer false-positive Warning fires when it should not

Comments

@seanm
Copy link

seanm commented Jan 10, 2025

Maybe I'm just not using it right, or not understanding something, but OTOH TySan is new, and thus probably a bit buggy... I used creduce to create a C test case showing, I think, a false positive.

typedef struct {
	int len;
	char *list;
} str_list;

typedef struct {
	str_list infiles;
	char command;
} nt_opts;

int add_string(str_list *slist) {
	(void)(slist->list);
}

int process_opts(nt_opts *opts) {
	add_string(&opts->infiles);
}

void free_opts_mem(nt_opts *nopt) {
	(void)(nopt->infiles.list); // •••TySan warns here•••
}

void main(int argc, char *argv[]) {
	nt_opts opts;
	int rv = process_opts(&opts);
	free_opts_mem(&opts);
}

then I run:

(xcrun /Users/sean/llvm/llvm-install/bin/clang -w -g -fsanitize=type test.c && ./a.out)

and I get:

==4848==ERROR: TypeSanitizer: type-aliasing-violation on address 0x00016cfc71f0 (pc 0x000102e3b690 bp 0x00016cfc6ea0 sp 0x00016cfc6620 tid 24776816)
READ of size 8 at 0x00016cfc71f0 with type p1 omnipotent char (in <anonymous type> at offset 8) accesses an existing object of type p1 omnipotent char (in <anonymous type> at offset 8)
    #0 0x000102e3b68c in free_opts_mem test.c:20

Aside:

  • what is an "omnipotent char"?
  • what is "type p1" referring to?
@seanm
Copy link
Author

seanm commented Jan 10, 2025

@fhahn @gbMattN this may interest you.

Perhaps it is related to #120412 afterall?

@EugeneZelenko EugeneZelenko added compiler-rt:tysan Type sanitizer and removed new issue labels Jan 10, 2025
@seanm
Copy link
Author

seanm commented Jan 10, 2025

I forgot to say that the clang I built is from the #120412 PR.

@fhahn
Copy link
Contributor

fhahn commented Jan 10, 2025

@seanm thanks jumping in head first, the feedback is extremely valuable. TySan is experimental at this stage, and any issues reported help a lot getting it in good shape quickly.

what is an "omnipotent char"?
what is "type p1" referring to?

This is the terminology Clang uses to encode the type information for LLVM, which tysan uses verbatim. We could probably try better to translate the types to something closer related to the types in source

@fhahn fhahn added the false-positive Warning fires when it should not label Jan 10, 2025
@seanm
Copy link
Author

seanm commented Jan 10, 2025

This is the terminology Clang uses to encode the type information for LLVM, which tysan uses verbatim. We could probably try better to translate the types to something closer related to the types in source

Thanks. I've created #122522 to suggest some documentation ideas.

I think I'll have to stop playing with it for now, as best as I can tell at least 3/4 of the reports I'm seeing from TySan are variants of this reduced case. It's just too much noise for now.

Excited to try more later!

@gbMattN
Copy link
Contributor

gbMattN commented Jan 13, 2025

Perhaps it is related to #120412 afterall?

I can reproduce this on main, and it seems its fixed in #120412 which will be merged in as soon as the build tests pass!

@seanm
Copy link
Author

seanm commented Jan 13, 2025

Confirmed fixed. That got me down from 827 ERROR: TypeSanitizer to just 61 now.

The first of the 61 looks like a false positive to me too... I'll creduce it now...

@seanm
Copy link
Author

seanm commented Jan 14, 2025

The first of the 61 looks like a false positive to me too... I'll creduce it now...

#122934

@seanm seanm closed this as completed Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:tysan Type sanitizer false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

5 participants