[LLVMbugs] [Bug 8111] New: FoldingSetNodeID::AddString and endianness

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Sep 8 05:43:11 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=8111

           Summary: FoldingSetNodeID::AddString and endianness
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: fvbommel at wxs.nl
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=5471)
 --> (http://llvm.org/bugs/attachment.cgi?id=5471)
proposed patch

There's a bug in FoldingSetNodeID::AddString. On little-endian systems it
hashes unaligned strings in a different way than aligned strings.
=====
$ cat addstring-endianness.cpp 
#include "llvm/ADT/FoldingSet.h"
#include <cstdio>

using namespace llvm;
using namespace std;

int main() {
    FoldingSetNodeID a, b;
    // An aligned string
    string str1= "a test string";
    a.AddString(str1.c_str());
    printf("a: added '%s'\n", str1.c_str());

    // An unaligned string
    string str2 = ">" + str1;
    b.AddString(str2.c_str() + 1);
    printf("b: added '%s'\n", str2.c_str() + 1);

    printf("%08x\n", a.ComputeHash());
    printf("%08x\n", b.ComputeHash());
}
$ g++ addstring-endianness.cpp `llvm-config --cxxflags --ldflags --libs` -o
test && ./test
a: added 'a test string'
b: added 'a test string'
5393c06e
93b97eaf
=====

After applying the attached patch:
=====
$ g++ addstring-endianness.cpp `llvm-config --cxxflags --ldflags --libs` -o
test && ./test
a: added 'a test string'
b: added 'a test string'
5393c06e
5393c06e
=====

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list