From 42a9c0c80c23fa0de3e3b00fef0dfa6d85e18e55 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 24 May 2021 15:01:15 +0200 Subject: [PATCH] [lldb] Reland "Fix UB in half2float" to fix the ubsan bot. This relands part of the UB fix in 4b074b49be206306330076b9fa40632ef1960823. The original commit also added some additional tests that uncovered some other issues (see D102845). I landed all the passing tests in 48780527dd6820698f3537f5ebf76499030ee349 and this patch is now just fixing the UB in half2float. See D102846 for a proposed rewrite of the function. Original commit message: The added DumpDataExtractorTest uncovered that this is lshifting a negative integer which upsets ubsan and breaks the sanitizer bot. This patch just changes the variable we shift to be unsigned. --- lldb/source/Core/DumpDataExtractor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp index ec44e3481c1e..34c9353c9fea 100644 --- a/lldb/source/Core/DumpDataExtractor.cpp +++ b/lldb/source/Core/DumpDataExtractor.cpp @@ -52,7 +52,9 @@ static float half2float(uint16_t half) { float f; uint32_t u; } u; - int32_t v = (int16_t)half; + // Sign extend to 4 byte. + int32_t sign_extended = static_cast(half); + uint32_t v = static_cast(sign_extended); if (0 == (v & 0x7c00)) { u.u = v & 0x80007FFFU;