diff options
Diffstat (limited to 'source/slang/slang-ir-link.cpp')
| -rw-r--r-- | source/slang/slang-ir-link.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index 2d497158d..88f385548 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -979,6 +979,12 @@ bool isBetterForTarget( IRInst* newVal, IRInst* oldVal) { + // Anything is better than nothing.. + if (oldVal == nullptr) + { + return true; + } + String targetName = getTargetName(context); // For right now every declaration might have zero or more @@ -1000,7 +1006,7 @@ bool isBetterForTarget( // (A and B and C) or (A and D) or (E) or (F and G) ... // // A code generation target would then consist of a - // conjunction of invidual tags: + // conjunction of individual tags: // // (HLSL and SM_4_0 and Vertex and ...) // @@ -1012,6 +1018,7 @@ bool isBetterForTarget( // of the other's. auto newLevel = getTargetSpecialiationLevel(newVal, targetName); + auto oldLevel = getTargetSpecialiationLevel(oldVal, targetName); if(newLevel != oldLevel) return UInt(newLevel) > UInt(oldLevel); @@ -1182,18 +1189,23 @@ IRInst* cloneGlobalValueWithLinkage( // We will try to track the "best" declaration we can find. // - // Generally, one declaration wil lbe better than another if it is + // Generally, one declaration will be better than another if it is // more specialized for the chosen target. Otherwise, we simply favor // definitions over declarations. // - IRInst* bestVal = sym->irGlobalValue; - for( auto ss = sym->nextWithSameName; ss; ss = ss->nextWithSameName ) + IRInst* bestVal = nullptr; + for(IRSpecSymbol* ss = sym; ss; ss = ss->nextWithSameName ) { IRInst* newVal = ss->irGlobalValue; if(isBetterForTarget(context, newVal, bestVal)) bestVal = newVal; } + if (!bestVal) + { + return nullptr; + } + // Check if we've already cloned this value, for the case where // we didn't have an original value (just a name), but we've // now found a representative value. |
