[cfe-dev] debugging PCH failures on powerpc-darwin8

David Fang fang at csl.cornell.edu
Mon Dec 19 01:47:46 PST 2011


> 	I've been debugging the numerous failures in PCH tests seen in my
> powerpc-darwin8-g++-4.0.1 bootstrap of llvm/clang (release 3.0).
>
> Full build/test log:
> http://www.csl.cornell.edu/~fang/sw/llvm/llvm-clang-release-3.0-powerpc-darwin8-g++-4.0.1-fink-build-log.txt
>
> I've been running this failing test by hand:
> bin/llvm-lit -v
> ../llvm-3.0.src/tools/clang/test/CXX/expr/expr.unary/expr.unary.noexcept/cg.cpp
>
> My debug trail is here:
> http://paste.lisp.org/display/126363#4
>
> It looks like the point of failure during reading of the PCH file shows
> that a decl ID number 184549376 is read, which happens to be 0x0b000000.
> Tracing through the write-out of the PCH finds that ID 11 is written out
> once, or 0x0000000b.  Is it possible that the
> serialization/deserialization of these values got byte-swapped?
>
> The machine I'm running on is a powerpc G4, big-endian.
> CMakeCache.txt agrees:
> IS_BIG_ENDIAN:INTERNAL=1

I took a stab at byte-swapping in 
ASTDeclContextNameLookupTrait::ReadData() in ASTReader.cpp,
but any attempts to modify the location that contained 0x0b000000 resulted 
in a bus-error, so instead I added the byte-swap to
ASTDeclContextNameLookupTrait::EmitData() in ASTWriter.cpp, and not only 
did the expr.unary.noexcept/cg.cpp test PASS, but over 50 of the original 
77 failing tests also PASSED!

I've attached the patch I applied.  Can someone familiar with the AST/PCH 
serialization component examine why this patch works for me, and whether 
there's a "more correct" patch than what I've applied? Again, this patch 
fixes numerous PCH Decl ID out-of-range failures on powerpc-darwin8, 
bootstrapping with g++-4.0.1.

Improved test results after this patch:
http://paste.lisp.org/display/126363#9
(only 20 remaining failures)

Thanks,

Fang

-- 
David Fang
http://www.csl.cornell.edu/~fang/
-------------- next part --------------
--- llvm-3.0.src-orig/tools/clang/lib/Serialization/ASTWriter.cpp	2011-10-06 23:10:15.000000000 -0700
+++ llvm-3.0.src/tools/clang/lib/Serialization/ASTWriter.cpp	2011-12-18 15:13:25.000000000 -0800
@@ -2483,9 +2495,14 @@ class ASTDeclContextNameLookupTrait {
   void EmitData(raw_ostream& Out, key_type_ref,
                 data_type Lookup, unsigned DataLen) {
     uint64_t Start = Out.tell(); (void)Start;
     clang::io::Emit16(Out, Lookup.second - Lookup.first);
     for (; Lookup.first != Lookup.second; ++Lookup.first)
-      clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first));
+    {
+      const uint32_t ref = Writer.GetDeclRef(*Lookup.first);
+//    byte-swap fixes tons of PCH failures on powerpc-darwin8
+      clang::io::Emit32(Out, llvm::ByteSwap_32(ref));
+//      clang::io::Emit32(Out, ref);
+    }
 
     assert(Out.tell() - Start == DataLen && "Data length is wrong");
   }


More information about the cfe-dev mailing list