From baa93d923a8386dc8d3d3db43dd17c4115ef8b29 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Tue, 16 Apr 2013 23:01:20 -0700 Subject: [PATCH] fix Issue 9209 - ice(symbol.c) with const struct heap allocation --- src/optimize.c | 7 ++++++ test/runnable/imports/inline2a.d | 38 ++++++++++++++++---------------- test/runnable/testconst.d | 12 ++++++++++ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/optimize.c b/src/optimize.c index c6191322cfc1..fe89ccb9e04c 100644 --- a/src/optimize.c +++ b/src/optimize.c @@ -104,6 +104,13 @@ Expression *expandVar(int result, VarDeclaration *v) else goto L1; } + else if (!(result & WANTinterpret) && + !(v->storage_class & STCmanifest) && + ei->isConst() != 1 && ei->op != TOKstring && + ei->op != TOKaddress) + { + goto L1; + } if (!ei->type) { goto L1; diff --git a/test/runnable/imports/inline2a.d b/test/runnable/imports/inline2a.d index b7ab9a76c957..c0f4d173e963 100644 --- a/test/runnable/imports/inline2a.d +++ b/test/runnable/imports/inline2a.d @@ -1,23 +1,23 @@ /******************************************************************************* @file Primes.d - + Copyright (C) 2004 Kris Bell - + This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for damages of any kind arising from the use of this software. - - Permission is hereby granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and/or + + Permission is hereby granted to anyone to use this software for any + purpose, including commercial applications, and to alter it and/or redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment within documentation of + + 1. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment within documentation of said product would be appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must + 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any distribution @@ -26,8 +26,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - @version Initial version, April 2004 + + @version Initial version, April 2004 @author Kris @@ -39,7 +39,7 @@ module imports.inline2a; class Primes { private - static const short primes[] = + static const short primes[] = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, @@ -149,14 +149,14 @@ class Primes *********************************************************************/ - private static int bsearch (in short[] array, short match) + private static ptrdiff_t bsearch (in short[] array, short match) { - int l, u, m; - + ptrdiff_t l, u, m; + l = -1; - u = cast(int)array.length; + u = array.length; - while (l+1 != u) + while (l+1 != u) { m = (l + u) / 2; if (array[m] < match) @@ -173,7 +173,7 @@ class Primes /********************************************************************** return a prime number between 2 and 7919 (inclusive) that - is equal to or larger than the given 'target' number. + is equal to or larger than the given 'target' number. **********************************************************************/ diff --git a/test/runnable/testconst.d b/test/runnable/testconst.d index 1d974f0900ef..4570bf248cd4 100644 --- a/test/runnable/testconst.d +++ b/test/runnable/testconst.d @@ -2957,6 +2957,17 @@ void test9461() /************************************/ +struct S9209 { int x; } + +void bar9209(const S9209*) {} + +void test9209() { + const f = new S9209(1); + bar9209(f); +} + +/************************************/ + int main() { test1(); @@ -3079,6 +3090,7 @@ int main() test9046(); test9090(); test9461(); + test9209(); printf("Success\n"); return 0;