tcsh/tcsh-6.19.00-003-avoid-gcc5-calloc-optimization.patch
David Kaspar [Dee'Kej] 3b4edba158 tcsh-6.19.00-003-avoid-gcc5-calloc-optimization.patch added
> avoid gcc-5 optimization malloc + memset = calloc (Fridolin Pokorny)
2016-05-03 17:11:23 +02:00

60 lines
1.2 KiB
Diff

From 624d3aebb6e6afadb4f35e894d11b5ebe290cd87 Mon Sep 17 00:00:00 2001
From: christos <christos>
Date: Thu, 28 May 2015 11:47:03 +0000
Subject: [PATCH 1/2] avoid gcc-5 optimization malloc + memset = calloc
(Fridolin Pokorny)
---
tc.alloc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tc.alloc.c b/tc.alloc.c
index b9aec63..c1cb330 100644
--- a/tc.alloc.c
+++ b/tc.alloc.c
@@ -348,10 +348,13 @@ calloc(size_t i, size_t j)
{
#ifndef lint
char *cp;
+ size_t k;
i *= j;
cp = xmalloc(i);
- memset(cp, 0, i);
+ /* Stop gcc 5.x from optimizing malloc+memset = calloc */
+ k = i;
+ memset(cp, 0, k);
return ((memalign_t) cp);
#else
--
2.5.5
From 05e7406049bd2686dee0ee8d819dcd38eb131f6f Mon Sep 17 00:00:00 2001
From: christos <christos>
Date: Tue, 7 Jul 2015 12:24:54 +0000
Subject: [PATCH 2/2] make k volatile to prevent gcc-5 memset() optimization
(Fridolin Pokorny)
---
tc.alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tc.alloc.c b/tc.alloc.c
index c1cb330..f68a8c5 100644
--- a/tc.alloc.c
+++ b/tc.alloc.c
@@ -348,7 +348,7 @@ calloc(size_t i, size_t j)
{
#ifndef lint
char *cp;
- size_t k;
+ volatile size_t k;
i *= j;
cp = xmalloc(i);
--
2.5.5