[PATCH] gcc: configure: Fix the optimization flags cleanup

2024-02-02 Thread Slava Barinov
Currently sed command in flag cleanup removes all the -O[0-9] flags, ignoring
the context. This leads to issues when the optimization flags is passed to
linker:

CFLAGS="-Os -Wl,-O1 -Wl,--hash-style=gnu"
is converted into
CFLAGS="-Os -Wl,-Wl,--hash-style=gnu"

Which leads to configure failure with ld: unrecognized option '-Wl,-Wl'.

gcc/
* configure.ac: Only remove -O[0-9] if not preceded with comma
* configure: Regenerated
---
 gcc/configure| 4 ++--
 gcc/configure.ac | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index c83e09beea9..fd72034cbc1 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -5472,8 +5472,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 # optimizations to be activated explicitly by the toplevel.
 case "$CC" in
   */prev-gcc/xgcc*) ;;
-  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/-O[0-9]*[]//" `
- CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/-O[0-9]*[]//" ` ;;
+  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/[^,]-O[0-9]*[]//" `
+ CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/[^,]-O[0-9]*[]//" ` ;;
 esac
 
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 239856a4e20..d62d630d9b7 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -467,8 +467,8 @@ AC_LANG(C++)
 # optimizations to be activated explicitly by the toplevel.
 case "$CC" in
   */prev-gcc/xgcc*) ;;
-  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/-O[[0-9]]*[[]]//" `
- CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/-O[[0-9]]*[[]]//" ` ;;
+  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/[[^,]]-O[[0-9]]*[[  ]]//" `
+ CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/[[^,]]-O[[0-9]]*[[  ]]//" ` ;;
 esac
 AC_SUBST(CFLAGS)
 AC_SUBST(CXXFLAGS)
-- 
2.43.0



[PATCH] c++/93730 create VLA constructor if explicitly initialized as zeroes

2020-02-19 Thread Slava Barinov
* cp/decl.c (reshape_init_array_1): Enforce constructor creation
for VLAs when initialized with zero value.
* testsuite/g++.dg/pr93730.C: New test
* testsuite/g++.dg/abi/mangle72.C: Change mangling to new version

Signed-off-by: Slava Barinov 

This fixes case when VLA is explicitly initialized with zero, not generic issue
c++/58646 though.

Bootstrapped on x86_64, no testsuite regressions found, except mangling change
in mangle72.C, Not sure about mangling: is there any ABI requirements to
mangling for that cases?

---
 gcc/ChangeLog   |  8 
 gcc/cp/decl.c   |  3 ++-
 gcc/testsuite/g++.dg/abi/mangle72.C | 14 +++---
 gcc/testsuite/g++.dg/pr93730.C  |  8 
 4 files changed, 25 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr93730.C

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f5876a3023e..10fa0334ec3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2020-02-20  Vyacheslav Barinov  
+
+   PR c++/93730
+   * cp/decl.c (reshape_init_array_1): Enforce constructor creation
+   for VLAs when initialized with zero value.
+   * testsuite/g++.dg/pr93730.C: New test
+   * testsuite/g++.dg/abi/mangle72.C: Change mangling to new version
+
 2020-02-19  Bernd Edlinger  
 
* collect2.c (maybe_run_lto_and_relink): Fix typo in
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 31a556a0a1f..e90a397fc11 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6043,7 +6043,8 @@ reshape_init_array_1 (tree elt_type, tree max_index, 
reshape_iter *d,
 even if the string is empty.  */
   tree init_type = TREE_TYPE (elt_init);
   if (POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type)
- || !type_initializer_zero_p (elt_type, elt_init))
+ || !type_initializer_zero_p (elt_type, elt_init)
+ || sized_array_p)
last_nonzero = index;
 
   /* This can happen with an invalid initializer (c++/54501).  */
diff --git a/gcc/testsuite/g++.dg/abi/mangle72.C 
b/gcc/testsuite/g++.dg/abi/mangle72.C
index 656a0cae403..928a38da021 100644
--- a/gcc/testsuite/g++.dg/abi/mangle72.C
+++ b/gcc/testsuite/g++.dg/abi/mangle72.C
@@ -27,16 +27,16 @@ void g__ (Y) { }
 // { dg-final { scan-assembler "_Z3g__1YIXtl1BtlA2_M1AA2_iLS3_0E" } }
 
 void g0_ (Y) { }
-// { dg-final { scan-assembler "_Z3g0_1YIXtl1BtlA2_M1AA2_iLS3_0E" } }
+// { dg-final { scan-assembler "_Z3g0_1YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0E" } }
 
 void g00 (Y) { }
-// { dg-final { scan-assembler "_Z3g001YIXtl1BtlA2_M1AA2_iLS3_0E" } }
+// { dg-final { scan-assembler "_Z3g001YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0E" } }
 
 void g0x (Y) { }
 // FIXME: This needs to mangle differently from g00.  The space at
 // the end is intentional to make the directive fail so that the xfail
 // can be reminder to change this once the mangling is fixed.
-// { dg-final { scan-assembler "_Z3g0x1YIXtl1BtlA2_M1AA2_iLS3_0E " { xfail 
*-*-* } } }
+// { dg-final { scan-assembler "_Z3g0x1YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0E " { 
xfail *-*-* } } }
 
 void gx_ (Y) { }
 // { dg-final { scan-assembler "_Z3gx_1YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0E" } }
@@ -49,17 +49,17 @@ void h___ (Z) { }
 // { dg-final { scan-assembler "_Z4h___1ZIXtl1CtlA3_M1AA2_iLS3_0E" } }
 
 void h0__ (Z) { }
-// { dg-final { scan-assembler "_Z4h0__1ZIXtl1CtlA3_M1AA2_iLS3_0E" } }
+// { dg-final { scan-assembler "_Z4h0__1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0E" } 
}
 
 void h00_ (Z) { }
-// { dg-final { scan-assembler "_Z4h00_1ZIXtl1CtlA3_M1AA2_iLS3_0E" } }
+// { dg-final { scan-assembler 
"_Z4h00_1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0E" } }
 
 void h000 (Z) { }
-// { dg-final { scan-assembler "_Z4h0001ZIXtl1CtlA3_M1AA2_iLS3_0E" } }
+// { dg-final { scan-assembler 
"_Z4h0001ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0E" } }
 
 void h00x (Z) { }
 // FIXME: This needs to mangle differently from hx0_ and hx__.
-// { dg-final { scan-assembler "_Z4h00x1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0E " 
{ xfail *-*-*} } }
+// { dg-final { scan-assembler 
"_Z4h00x1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0E " { xfail *-*-*} } }
 
 void h0x0 (Z) { }
 // { dg-final { scan-assembler 
"_Z4h0x01ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0E" } }
diff --git a/gcc/testsuite/g++.dg/pr93730.C b/gcc/testsuite/g++.dg/pr93730.C
new file mode 100644
index 000..066c23a99cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr93730.C
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-Wno-vla" } */
+
+int sz = 1;
+
+void f() {
+  int arr[1][sz] = { 0 };
+}
-- 
2.25.1



[PATCH] Switch on *.cc tests for g++ ASan

2017-08-07 Thread Slava Barinov
* g++.dg/asan/asan.exp: Switch on *.cc tests.

Signed-off-by: Slava Barinov 
---
 gcc/testsuite/ChangeLog| 4 
 gcc/testsuite/g++.dg/asan/asan.exp | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c2119f478ba..315af8361df 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-08  Vyacheslav Barinov  
+
+   * g++.dg/asan/asan.exp: Switch on *.cc tests.
+
 2017-08-07  Michael Meissner  
 
PR target/81593
diff --git a/gcc/testsuite/g++.dg/asan/asan.exp 
b/gcc/testsuite/g++.dg/asan/asan.exp
index 124c44e9e9a..620071ba7dc 100644
--- a/gcc/testsuite/g++.dg/asan/asan.exp
+++ b/gcc/testsuite/g++.dg/asan/asan.exp
@@ -26,7 +26,7 @@ asan_init
 
 # Main loop.
 if [check_effective_target_fsanitize_address] {
-  gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C 
$srcdir/c-c++-common/asan/*.c]] "" ""
+  gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C 
$srcdir/$subdir/*.cc $srcdir/c-c++-common/asan/*.c]] "" ""
 }
 
 # All done.
-- 
2.13.3



[PATCH] Forbid section anchors for ASan build (PR sanitizer/81697)

2017-08-07 Thread Slava Barinov
   gcc/
   * varasm.c (use_object_blocks_p): Forbid section anchors for ASan

   gcc/testsuite/
   * g++.dg/asan/global-alignment.cc: New test to test global
   variables alignment.

Signed-off-by: Slava Barinov 
---
 gcc/ChangeLog |  6 ++
 gcc/testsuite/ChangeLog   |  3 +++
 gcc/testsuite/g++.dg/asan/global-alignment.cc | 17 +
 gcc/varasm.c  |  3 ++-
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/asan/global-alignment.cc

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index dde91ceea5b..d840825e7c8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-08-08  Vyacheslav Barinov  
+
+   PR sanitizer/81697
+   * varasm.c (use_object_blocks_p): Forbid section anchors for ASan
+   build.
+
 2017-08-08  Martin Liska  
 
* asan.c: Include header files.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 315af8361df..0a0a5850c74 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2017-08-08  Vyacheslav Barinov  
 
+   PR sanitizer/81697
+   * g++.dg/asan/global-alignment.cc: New test to test global
+   variables alignment.
* g++.dg/asan/asan.exp: Switch on *.cc tests.
 
 2017-08-07  Michael Meissner  
diff --git a/gcc/testsuite/g++.dg/asan/global-alignment.cc 
b/gcc/testsuite/g++.dg/asan/global-alignment.cc
new file mode 100644
index 000..c011c703ea6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/global-alignment.cc
@@ -0,0 +1,17 @@
+/* { dg-options "-fmerge-all-constants" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
+
+#include 
+#include 
+
+const char kRecoveryInstallString[] = "NEW";
+const char kRecoveryUpdateString[] = "UPDATE";
+const char kRecoveryUninstallationString[] = "UNINSTALL";
+
+const std::map kStringToRequestMap = {
+  {kRecoveryInstallString, 0},
+  {kRecoveryUpdateString, 0},
+  {kRecoveryUninstallationString, 0},
+};
+/* { dg-final { scan-assembler-times 
{\.section\s+\.rodata\n(?:(?!\.section).)*\.(string|ascii|asciz)\s+"NEW} 1 } } 
*/
diff --git a/gcc/varasm.c b/gcc/varasm.c
index e0834a1ff3b..dbeb8d9331e 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -346,7 +346,8 @@ get_section (const char *name, unsigned int flags, tree 
decl)
 static bool
 use_object_blocks_p (void)
 {
-  return flag_section_anchors;
+  return (flag_section_anchors
+ && !(flag_sanitize & SANITIZE_ADDRESS));
 }
 
 /* Return the object_block structure for section SECT.  Create a new
-- 
2.13.3



[PATCH] libsanitizer: fix SIGSEGV in fopen64 interceptor

2020-11-19 Thread Slava Barinov via Gcc-patches
Null pointer in path argument leads to SIGSEGV in interceptor.

libsanitizer/ChangeLog:
* sanitizer_common/sanitizer_common_interceptors.inc: Check
path for null before dereference in fopen64 interceptor.
---

Notes:
Apparently check has been lost during merge from upstream

 libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc 
b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
index 729eead43c0..2ef23d9a50b 100644
--- a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
@@ -6081,7 +6081,7 @@ INTERCEPTOR(__sanitizer_FILE *, freopen, const char 
*path, const char *mode,
 INTERCEPTOR(__sanitizer_FILE *, fopen64, const char *path, const char *mode) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, fopen64, path, mode);
-  COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
   COMMON_INTERCEPTOR_READ_RANGE(ctx, mode, REAL(strlen)(mode) + 1);
   __sanitizer_FILE *res = REAL(fopen64)(path, mode);
   COMMON_INTERCEPTOR_FILE_OPEN(ctx, res, path);
-- 
2.29.2