Skip to content

Conversation

bulbazord
Copy link
Member

The implementation of the templated Get function contains UB. For example, the "GetDoubleUnaligned" unit test causes Get to perform an unaligned 8 byte read. This violates the double alignment requirement. Furthermore, it violates strict aliasing rules in C++. (We construct a const double * from a const uint8_t * and perform a read on the resulting double pointer).

DataExtractor should be able to read unaligned data to deal with different data formats, but we need to be careful to not perform unaligned reads/writes or violate strict aliasing rules.

rdar://160385383

The implementation of the templated `Get` function contains UB. For
example, the "GetDoubleUnaligned" unit test causes `Get` to perform an
unaligned 8 byte read. This violates the `double` alignment requirement.
Furthermore, it violates strict aliasing rules in C++. (We construct a
`const double *` from a `const uint8_t *` and perform a read on the
resulting double pointer).

DataExtractor should be able to read unaligned data to deal with
different data formats, but we need to be careful to not perform
unaligned reads/writes or violate strict aliasing rules.

rdar://160385383
@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2025

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

Changes

The implementation of the templated Get function contains UB. For example, the "GetDoubleUnaligned" unit test causes Get to perform an unaligned 8 byte read. This violates the double alignment requirement. Furthermore, it violates strict aliasing rules in C++. (We construct a const double * from a const uint8_t * and perform a read on the resulting double pointer).

DataExtractor should be able to read unaligned data to deal with different data formats, but we need to be careful to not perform unaligned reads/writes or violate strict aliasing rules.

rdar://160385383


Full diff: https://github.com/llvm/llvm-project/pull/163880.diff

1 Files Affected:

  • (modified) lldb/include/lldb/Utility/DataExtractor.h (+1-1)
diff --git a/lldb/include/lldb/Utility/DataExtractor.h b/lldb/include/lldb/Utility/DataExtractor.h
index 0b7e771ed4f86..b4960f5e87c85 100644
--- a/lldb/include/lldb/Utility/DataExtractor.h
+++ b/lldb/include/lldb/Utility/DataExtractor.h
@@ -994,7 +994,7 @@ class DataExtractor {
     constexpr size_t src_size = sizeof(T);
     T val = fail_value;
 
-    const T *src = static_cast<const T *>(GetData(offset_ptr, src_size));
+    const void *src = GetData(offset_ptr, src_size);
     if (!src)
       return val;
 

@bulbazord bulbazord merged commit 40d4ea6 into llvm:main Oct 17, 2025
12 checks passed
@bulbazord bulbazord deleted the unaligned-data-extractor-read branch October 17, 2025 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants