* A fix to get the higher optimisation levels (-O2, -O3) to work again

for the ATerm library.  I'm adding it to Nixpkgs so we can get some
  testing ;-)

svn path=/nixpkgs/trunk/; revision=2979
This commit is contained in:
Eelco Dolstra 2005-05-02 16:57:13 +00:00
parent 9594c8eb5b
commit fe6f8b45e6
2 changed files with 484 additions and 0 deletions

View File

@ -0,0 +1,482 @@
diff -rc aterm-2.3.1-orig/aterm/aterm.c aterm-2.3.1/aterm/aterm.c
*** aterm-2.3.1-orig/aterm/aterm.c 2004-06-01 10:29:01.000000000 +0200
--- aterm-2.3.1/aterm/aterm.c 2005-05-02 18:32:52.000000000 +0200
***************
*** 191,196 ****
--- 191,197 ----
/* that have char == 2 bytes, and sizeof(header_type) == 2 */
assert(sizeof(header_type) == sizeof(ATerm *));
assert(sizeof(header_type) >= 4);
+ assert(sizeof(ATerm) == sizeof(MachineWord));
/*}}} */
/*{{{ Initialize buffer */
diff -rc aterm-2.3.1-orig/aterm/memory.c aterm-2.3.1/aterm/memory.c
*** aterm-2.3.1-orig/aterm/memory.c 2004-06-09 10:52:33.000000000 +0200
--- aterm-2.3.1/aterm/memory.c 2005-05-02 18:32:52.000000000 +0200
***************
*** 176,182 ****
* Static arrays are not guaranteed to be sizeof(double)-aligned.
*/
static MachineWord *protoTerm = NULL;
- static ATerm *arg_buffer = NULL;
static ATerm protected_buffer[MAX_ARITY] = { NULL };
--- 176,181 ----
***************
*** 495,501 ****
HashNumber hnr;
protoTerm = (MachineWord *) calloc(MAX_TERM_SIZE, sizeof(MachineWord));
- arg_buffer = (ATerm *) (protoTerm + 2);
/*{{{ Analyze arguments */
--- 494,499 ----
***************
*** 1032,1043 ****
va_list args;
protoAppl = (ATermAppl) protoTerm;
-
va_start(args, sym);
for (i=0; i<arity; i++) {
! arg_buffer[i] = va_arg(args, ATerm);
! protected_buffer[i] = arg_buffer[i];
! CHECK_TERM(arg_buffer[i]);
}
va_end(args);
--- 1030,1040 ----
va_list args;
protoAppl = (ATermAppl) protoTerm;
va_start(args, sym);
for (i=0; i<arity; i++) {
! protected_buffer[i] = va_arg(args, ATerm);
! protoTerm[ARG_OFFSET + i] = (MachineWord) protected_buffer[i];
! CHECK_TERM(protected_buffer[i]);
}
va_end(args);
***************
*** 1055,1061 ****
appl = (ATermAppl)cur;
found = ATtrue;
for (i=0; i<arity; i++) {
! if (!ATisEqual(ATgetArgument(appl, i), arg_buffer[i])) {
found = ATfalse;
break;
}
--- 1052,1058 ----
appl = (ATermAppl)cur;
found = ATtrue;
for (i=0; i<arity; i++) {
! if (!ATisEqual(ATgetArgument(appl, i), protoTerm[ARG_OFFSET + i])) {
found = ATfalse;
break;
}
***************
*** 1073,1079 ****
cur->header = header;
CHECK_HEADER(cur->header);
for (i=0; i<arity; i++) {
! ATgetArgument(cur, i) = arg_buffer[i];
CHECK_ARGUMENT(cur, i);
}
cur->next = hashtable[hnr];
--- 1070,1076 ----
cur->header = header;
CHECK_HEADER(cur->header);
for (i=0; i<arity; i++) {
! ATgetArgument(cur, i) = (ATerm) protoTerm[ARG_OFFSET + i];
CHECK_ARGUMENT(cur, i);
}
cur->next = hashtable[hnr];
***************
*** 1164,1170 ****
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! arg_buffer[0] = arg0;
hnr = HASHNUMBER3((ATerm) protoAppl);
prev = NULL;
--- 1161,1167 ----
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! protoTerm[ARG_OFFSET + 0] = (MachineWord) arg0;
hnr = HASHNUMBER3((ATerm) protoAppl);
prev = NULL;
***************
*** 1225,1232 ****
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! arg_buffer[0] = arg0;
! arg_buffer[1] = arg1;
hnr = HASHNUMBER4((ATerm) protoAppl);
prev = NULL;
--- 1222,1229 ----
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! protoTerm[ARG_OFFSET + 0] = (MachineWord) arg0;
! protoTerm[ARG_OFFSET + 1] = (MachineWord) arg1;
hnr = HASHNUMBER4((ATerm) protoAppl);
prev = NULL;
***************
*** 1287,1295 ****
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! arg_buffer[0] = arg0;
! arg_buffer[1] = arg1;
! arg_buffer[2] = arg2;
hnr = hash_number((ATerm) protoAppl, 5);
cur = hashtable[hnr & table_mask];
--- 1284,1292 ----
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! protoTerm[ARG_OFFSET + 0] = (MachineWord) arg0;
! protoTerm[ARG_OFFSET + 1] = (MachineWord) arg1;
! protoTerm[ARG_OFFSET + 2] = (MachineWord) arg2;
hnr = hash_number((ATerm) protoAppl, 5);
cur = hashtable[hnr & table_mask];
***************
*** 1347,1356 ****
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! arg_buffer[0] = arg0;
! arg_buffer[1] = arg1;
! arg_buffer[2] = arg2;
! arg_buffer[3] = arg3;
hnr = hash_number((ATerm) protoAppl, 6);
cur = hashtable[hnr & table_mask];
--- 1344,1353 ----
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! protoTerm[ARG_OFFSET + 0] = (MachineWord) arg0;
! protoTerm[ARG_OFFSET + 1] = (MachineWord) arg1;
! protoTerm[ARG_OFFSET + 2] = (MachineWord) arg2;
! protoTerm[ARG_OFFSET + 3] = (MachineWord) arg3;
hnr = hash_number((ATerm) protoAppl, 6);
cur = hashtable[hnr & table_mask];
***************
*** 1411,1421 ****
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! arg_buffer[0] = arg0;
! arg_buffer[1] = arg1;
! arg_buffer[2] = arg2;
! arg_buffer[3] = arg3;
! arg_buffer[4] = arg4;
hnr = hash_number((ATerm) protoAppl, 7);
cur = hashtable[hnr & table_mask];
--- 1408,1418 ----
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! protoTerm[ARG_OFFSET + 0] = (MachineWord) arg0;
! protoTerm[ARG_OFFSET + 1] = (MachineWord) arg1;
! protoTerm[ARG_OFFSET + 2] = (MachineWord) arg2;
! protoTerm[ARG_OFFSET + 3] = (MachineWord) arg3;
! protoTerm[ARG_OFFSET + 4] = (MachineWord) arg4;
hnr = hash_number((ATerm) protoAppl, 7);
cur = hashtable[hnr & table_mask];
***************
*** 1479,1490 ****
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! arg_buffer[0] = arg0;
! arg_buffer[1] = arg1;
! arg_buffer[2] = arg2;
! arg_buffer[3] = arg3;
! arg_buffer[4] = arg4;
! arg_buffer[5] = arg5;
hnr = hash_number((ATerm) protoAppl, 8);
cur = hashtable[hnr & table_mask];
--- 1476,1487 ----
protoAppl = (ATermAppl) protoTerm;
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! protoTerm[ARG_OFFSET + 0] = (MachineWord) arg0;
! protoTerm[ARG_OFFSET + 1] = (MachineWord) arg1;
! protoTerm[ARG_OFFSET + 2] = (MachineWord) arg2;
! protoTerm[ARG_OFFSET + 3] = (MachineWord) arg3;
! protoTerm[ARG_OFFSET + 4] = (MachineWord) arg4;
! protoTerm[ARG_OFFSET + 5] = (MachineWord) arg5;
hnr = hash_number((ATerm) protoAppl, 8);
cur = hashtable[hnr & table_mask];
***************
*** 1552,1558 ****
CHECK_HEADER(protoAppl->header);
for (i=0; i<arity; i++) {
! arg_buffer[i] = ATgetFirst(args);
args = ATgetNext(args);
}
--- 1549,1555 ----
CHECK_HEADER(protoAppl->header);
for (i=0; i<arity; i++) {
! protoTerm[ARG_OFFSET + i] = (MachineWord) ATgetFirst(args);
args = ATgetNext(args);
}
***************
*** 1567,1573 ****
found = ATtrue;
for(i=0; i<arity; i++)
{
! if(!ATisEqual(ATgetArgument(appl, i), arg_buffer[i]))
{
found = ATfalse;
break;
--- 1564,1570 ----
found = ATtrue;
for(i=0; i<arity; i++)
{
! if(!ATisEqual(ATgetArgument(appl, i), protoTerm[ARG_OFFSET + i]))
{
found = ATfalse;
break;
***************
*** 1587,1593 ****
cur->header = header;
CHECK_HEADER(cur->header);
for (i=0; i<arity; i++) {
! ATgetArgument(cur, i) = arg_buffer[i];
CHECK_ARGUMENT(cur, i);
}
cur->next = hashtable[hnr];
--- 1584,1590 ----
cur->header = header;
CHECK_HEADER(cur->header);
for (i=0; i<arity; i++) {
! ATgetArgument(cur, i) = (ATerm) protoTerm[ARG_OFFSET + i];
CHECK_ARGUMENT(cur, i);
}
cur->next = hashtable[hnr];
***************
*** 1623,1632 ****
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! if (args != arg_buffer) {
for (i=0; i<arity; i++) {
CHECK_TERM(args[i]);
! arg_buffer[i] = args[i];
protected_buffer[i] = args[i];
}
}
--- 1620,1629 ----
protoAppl->header = header;
CHECK_HEADER(protoAppl->header);
! if (args != (ATerm *) (protoTerm + ARG_OFFSET)) {
for (i=0; i<arity; i++) {
CHECK_TERM(args[i]);
! protoTerm[ARG_OFFSET + i] = (MachineWord) args[i];
protected_buffer[i] = args[i];
}
}
***************
*** 1639,1645 ****
appl = (ATermAppl)cur;
found = ATtrue;
for(i=0; i<arity; i++) {
! if(!ATisEqual(ATgetArgument(appl, i), arg_buffer[i])) {
found = ATfalse;
break;
}
--- 1636,1642 ----
appl = (ATermAppl)cur;
found = ATtrue;
for(i=0; i<arity; i++) {
! if(!ATisEqual(ATgetArgument(appl, i), protoTerm[ARG_OFFSET + i])) {
found = ATfalse;
break;
}
***************
*** 1657,1670 ****
cur->header = header;
CHECK_HEADER(cur->header);
for (i=0; i<arity; i++) {
! ATgetArgument(cur, i) = arg_buffer[i];
CHECK_ARGUMENT(cur, i);
}
cur->next = hashtable[hnr];
hashtable[hnr] = cur;
}
! if (args != arg_buffer) {
for (i=0; i<arity; i++) {
protected_buffer[i] = NULL;
}
--- 1654,1667 ----
cur->header = header;
CHECK_HEADER(cur->header);
for (i=0; i<arity; i++) {
! ATgetArgument(cur, i) = (ATerm) protoTerm[ARG_OFFSET + i];
CHECK_ARGUMENT(cur, i);
}
cur->next = hashtable[hnr];
hashtable[hnr] = cur;
}
! if (args != (ATerm *) (protoTerm + ARG_OFFSET)) {
for (i=0; i<arity; i++) {
protected_buffer[i] = NULL;
}
***************
*** 2122,2132 ****
assert(n >= 0 && n < arity);
for (i=0; i<arity; i++) {
! arg_buffer[i] = ATgetArgument(appl, i);
}
! arg_buffer[n] = arg;
! result = ATmakeApplArray(sym, arg_buffer);
annos = AT_getAnnotations((ATerm)appl);
if (annos != NULL) {
result = (ATermAppl)AT_setAnnotations((ATerm)result, annos);
--- 2119,2129 ----
assert(n >= 0 && n < arity);
for (i=0; i<arity; i++) {
! protoTerm[ARG_OFFSET + i] = (MachineWord) ATgetArgument(appl, i);
}
! protoTerm[ARG_OFFSET + n] = (MachineWord) arg;
! result = ATmakeApplArray(sym, (ATerm *) (protoTerm + ARG_OFFSET));
annos = AT_getAnnotations((ATerm)appl);
if (annos != NULL) {
result = (ATermAppl)AT_setAnnotations((ATerm)result, annos);
diff -rc aterm-2.3.1-orig/configure aterm-2.3.1/configure
*** aterm-2.3.1-orig/configure 2004-12-01 23:03:59.000000000 +0100
--- aterm-2.3.1/configure 2005-05-02 18:36:24.000000000 +0200
***************
*** 2890,2896 ****
INCL_PROF=""
CC_NS=gcc
! CFLAGS_NS="-Wall -DNDEBUG -O -DXGC_VERBOSE -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
LFLAGS_NS=""
DEFS_NS="\$(DEFS) -DNO_SHARING"
INCL_NS=""
--- 2890,2896 ----
INCL_PROF=""
CC_NS=gcc
! CFLAGS_NS="-Wall -DNDEBUG -O3 -DXGC_VERBOSE -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
LFLAGS_NS=""
DEFS_NS="\$(DEFS) -DNO_SHARING"
INCL_NS=""
***************
*** 3379,3385 ****
CFLAGS=${withval}
else
if test "a${GCC}" = "ayes"; then
! CFLAGS="-Wall -DNDEBUG -O -DXGC_VERBOSE -DXHASHPEM -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
fi;
fi;
--- 3379,3385 ----
CFLAGS=${withval}
else
if test "a${GCC}" = "ayes"; then
! CFLAGS="-Wall -DNDEBUG -O3 -DXGC_VERBOSE -DXHASHPEM -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
fi;
fi;
diff -rc aterm-2.3.1-orig/configure.in aterm-2.3.1/configure.in
*** aterm-2.3.1-orig/configure.in 2004-09-16 13:45:27.000000000 +0200
--- aterm-2.3.1/configure.in 2005-05-02 18:32:12.000000000 +0200
***************
*** 35,41 ****
INCL_PROF=""
CC_NS=gcc
! CFLAGS_NS="-Wall -DNDEBUG -O -DXGC_VERBOSE -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
LFLAGS_NS=""
DEFS_NS="\$(DEFS) -DNO_SHARING"
INCL_NS=""
--- 35,41 ----
INCL_PROF=""
CC_NS=gcc
! CFLAGS_NS="-Wall -DNDEBUG -O3 -DXGC_VERBOSE -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
LFLAGS_NS=""
DEFS_NS="\$(DEFS) -DNO_SHARING"
INCL_NS=""
***************
*** 89,95 ****
[ --with-cflags=CFLAGS standard options of C compiler],
CFLAGS=${withval},
if test "a${GCC}" = "ayes"; then
! CFLAGS="-Wall -DNDEBUG -O -DXGC_VERBOSE -DXHASHPEM -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
fi;
)
--- 89,95 ----
[ --with-cflags=CFLAGS standard options of C compiler],
CFLAGS=${withval},
if test "a${GCC}" = "ayes"; then
! CFLAGS="-Wall -DNDEBUG -O3 -DXGC_VERBOSE -DXHASHPEM -DWITH_STATS" # " -O2" disabled due to gcc optimizer bugs
fi;
)
diff -rc aterm-2.3.1-orig/README aterm-2.3.1/README
*** aterm-2.3.1-orig/README 2002-01-16 14:19:35.000000000 +0100
--- aterm-2.3.1/README 2005-05-02 18:37:48.000000000 +0200
***************
*** 1,27 ****
- ***NOTE on COMPILER OPTIMIZATIONS:
-
- (added Wed, 16 Jan 2002, <jong@cwi.nl>)
-
- Due to several pending issues with the optimizer in the GNU C Compiler
- (most noticable to everyone using gcc version over 2.95), we strongly
- advise AGAINST passing gcc any of its '-O' optimization flags.
-
- More information on GCC optimization bugs can be found at:
- http://gcc.gnu.org/cgi-bin/gnatsweb.pl?database=gcc&cmd=query
-
- and subsequently selecting the Category:
- "optimization -- Issues related to optimization"
-
- As a result, the default configuration of the ATerm Library does not
- pass any optimizer flags to gcc anymore. Should you wish to experiment
- with specific compiler flags anyway, you can use the "--with-cflags"
- configure option. Your mileage may vary from the stress-test failing,
- to coredumps and spontaneous aborts in your program.
-
-
-
-
README with this version of the aterm library.
==============================================
--- 1,4 ----

View File

@ -8,4 +8,6 @@ stdenv.mkDerivation {
url = http://catamaran.labs.cs.uu.nl/dist/tarballs/aterm-2.3.1.tar.gz;
md5 = "5a2d70acc45a9d301e0dba12fcaf77e7";
};
patches = [ ./aterm-alias-fix.patch ];
}