llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.11k stars 12.01k forks source link

Non-determinism exposed by microsoft-abi-virtual-inheritance.cpp test #35507

Closed pcc closed 6 years ago

pcc commented 6 years ago
Bugzilla Link 36159
Resolution FIXED
Resolved on Mar 07, 2018 15:16
Version unspecified
OS Linux
CC @dwblaikie,@nico,@rnk

Extended Description

$ clang -cc1 -internal-isystem .../lib/clang/7.0.0/include -nostdsysteminc .../clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp -fno-rtti -std=c++11 -Wno-inaccessible-base -triple=i386-pc-win32 -emit-llvm -o - > /tmp/1 $ clang -cc1 -internal-isystem .../lib/clang/7.0.0/include -nostdsysteminc .../clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp -fno-rtti -std=c++11 -Wno-inaccessible-base -triple=i386-pc-win32 -emit-llvm -o - | diff -u /tmp/1 -

shows a diff most of the time, e.g.

--- /tmp/1 2018-01-30 17:18:22.750623402 -0800 +++ - 2018-01-30 17:28:37.603706299 -0800 @@ -618,10 +618,10 @@ %vbptr16 = getelementptr inbounds i8, i8 %35, i32 0 %36 = bitcast i8 %vbptr16 to i32* %vbtable17 = load i32, i32** %36, align 4

nico commented 6 years ago

r326960

nico commented 6 years ago

https://reviews.llvm.org/D44223

nico commented 6 years ago

For the vtordisp lines:

This walks VBaseMap in iteration order: http://llvm-cs.pcc.me.uk/tools/clang/lib/CodeGen/MicrosoftCXXABI.cpp#1199

for (VBOffsets::const_iterator I = VBaseMap.begin(), E = VBaseMap.end(); I != E; ++I) { ... }

VBaseMap has type ASTRecordLayout::VBaseOffsetsMapTy which is a llvm::DenseMap<const CXXRecordDecl *, VBaseInfo> -- so even if DenseMap promises sorted iteration order, it'd be sorted by pointer value.

The vbtableNs are probably from the same loop actually: The loop calls GetVirtualBaseClassOffset() which calls GetVBaseOffsetFromVBPtr() which creates the vbtableN vars.

The loop initializes some in-memory structures (it's in initializeHiddenVirtualInheritanceMembers()), and the nondeterminism only means that we do this in a different order. So we should fix it, but it's not a flaky miscompile.