Bug 84307 - asan blocks dead-store elimination
Summary: asan blocks dead-store elimination
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 7.3.1
: P3 normal
Target Milestone: ---
Assignee: Paolo Bonzini
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2018-02-09 12:25 UTC by Paolo Bonzini
Modified: 2018-11-20 08:17 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 7.3.1, 8.0.1
Last reconfirmed: 2018-02-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Bonzini 2018-02-09 12:25:39 UTC
For the following program, compilation with -O1 works, but compilation with -O1 -fsanitize=address fails.  clang works.

----
struct f {
    void (*func)(void);
};

extern void link_error(void);
extern int printf(const char *f, ...);

static inline struct f *gimme_null(struct f *result)
{
    return 0;
}

int main(int argc, char **argv)
{
    struct f *x = gimme_null(&(struct f) { .func = link_error });
    printf("%p", x);
}
----

Without -fsanitize=address, dse1 removes the dead store to the compound literal.  With -fsanitize=address, however, ASAN_MARK causes the compound literal to escape:

main (int argc, char * * argv)
{
  struct f * D.2139;
  struct f * x;
  struct f D.2129;

  <bb 2> [100.00%]:
  ASAN_MARK (UNPOISON, &D.2129, 8);
  D.2129.func = link_error;
  printf ("%p", 0B);
  return 0;
}
Comment 1 Paolo Bonzini 2018-02-12 12:48:31 UTC
Author: bonzini
Date: Mon Feb 12 12:47:56 2018
New Revision: 257585

URL: https://gcc.gnu.org/viewcvs?rev=257585&root=gcc&view=rev
Log:
gcc:
2018-02-12  Paolo Bonzini <bonzini@gnu.org>

	PR sanitizer/84307
	* internal-fn.def (ASAN_CHECK): Fix fnspec to account for return value.
	(ASAN_MARK): Fix fnspec to account for return value, change pointer
	argument from 'R' to 'W' so that the pointed-to datum is clobbered.

gcc/testsuite:
2018-02-12  Paolo Bonzini  <bonzini@gnu.org>

	PR sanitizer/84307
	* gcc.dg/asan/pr84307.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/asan/pr84307.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/internal-fn.def
    trunk/gcc/testsuite/ChangeLog
Comment 2 Paolo Bonzini 2018-02-13 13:03:54 UTC
Author: bonzini
Date: Tue Feb 13 13:03:22 2018
New Revision: 257625

URL: https://gcc.gnu.org/viewcvs?rev=257625&root=gcc&view=rev
Log:
gcc:
2018-02-13  Paolo Bonzini <bonzini@gnu.org>

	PR sanitizer/84340
	* internal-fn.def (ASAN_CHECK, ASAN_MARK): Revert changes to fnspec.

gcc/testsuite:
2018-02-13  Paolo Bonzini  <bonzini@gnu.org>

	PR sanitizer/84307
	* gcc.dg/asan/pr84307.c: Remove test.


Removed:
    trunk/gcc/testsuite/gcc.dg/asan/pr84307.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/internal-fn.def
    trunk/gcc/testsuite/ChangeLog
Comment 3 Paolo Bonzini 2018-02-13 13:05:48 UTC
Patch reverted due to PR84340.
Comment 4 Martin Liška 2018-02-16 10:04:18 UTC
Author: marxin
Date: Fri Feb 16 10:03:47 2018
New Revision: 257729

URL: https://gcc.gnu.org/viewcvs?rev=257729&root=gcc&view=rev
Log:
Set proper internal functions fnspec (PR sanitizer/84307).

2018-02-16  Martin Liska  <mliska@suse.cz>

	PR sanitizer/84307
	* internal-fn.def (ASAN_CHECK): Set proper flags.
	(ASAN_MARK): Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/internal-fn.def
Comment 5 Jakub Jelinek 2018-04-25 10:02:55 UTC
Author: jakub
Date: Wed Apr 25 10:02:24 2018
New Revision: 259641

URL: https://gcc.gnu.org/viewcvs?rev=259641&root=gcc&view=rev
Log:
	PR sanitizer/84307
	* c-decl.c (build_compound_literal): Call pushdecl (decl) even when
	it is not TREE_STATIC.
	* c-typeck.c (c_mark_addressable) <case COMPOUND_LITERAL_EXPR>: Mark
	not just the COMPOUND_LITERAL_EXPR node itself addressable, but also
	its COMPOUND_LITERAL_EXPR_DECL.

Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-decl.c
    trunk/gcc/c/c-typeck.c
Comment 6 Martin Liška 2018-11-20 08:14:03 UTC
Jakub: Can the bug be marked as resolved?
Comment 7 Jakub Jelinek 2018-11-20 08:17:58 UTC
Fixed for GCC 9 and later, no plans to backport it.