File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,8 @@ class SBType {
150
150
151
151
uint64_t GetByteSize ();
152
152
153
+ uint64_t GetByteAlign ();
154
+
153
155
bool IsPointerType ();
154
156
155
157
bool IsReferenceType ();
Original file line number Diff line number Diff line change 25
25
#include " lldb/Utility/Stream.h"
26
26
27
27
#include " llvm/ADT/APSInt.h"
28
+ #include " llvm/Support/MathExtras.h"
28
29
29
30
#include < memory>
30
31
#include < optional>
@@ -132,6 +133,18 @@ uint64_t SBType::GetByteSize() {
132
133
return 0 ;
133
134
}
134
135
136
+ uint64_t SBType::GetByteAlign () {
137
+ LLDB_INSTRUMENT_VA (this );
138
+
139
+ if (!IsValid ())
140
+ return 0 ;
141
+
142
+ std::optional<uint64_t > bit_align =
143
+ m_opaque_sp->GetCompilerType (/* prefer_dynamic=*/ false )
144
+ .GetTypeBitAlign (nullptr );
145
+ return llvm::divideCeil (bit_align.value_or (0 ), 8 );
146
+ }
147
+
135
148
bool SBType::IsPointerType () {
136
149
LLDB_INSTRUMENT_VA (this );
137
150
Original file line number Diff line number Diff line change @@ -272,3 +272,24 @@ def test(self):
272
272
self .assertTrue (int_enum_uchar )
273
273
self .DebugSBType (int_enum_uchar )
274
274
self .assertEqual (int_enum_uchar .GetName (), "unsigned char" )
275
+
276
+ def test_GetByteAlign (self ):
277
+ """Exercise SBType::GetByteAlign"""
278
+ self .build ()
279
+ spec = lldb .SBModuleSpec ()
280
+ spec .SetFileSpec (lldb .SBFileSpec (self .getBuildArtifact ()))
281
+ module = lldb .SBModule (spec )
282
+ self .assertTrue (module )
283
+
284
+ # Invalid types should not crash.
285
+ self .assertEqual (lldb .SBType ().GetByteAlign (), 0 )
286
+
287
+ # Try a type with natural alignment.
288
+ void_ptr = module .GetBasicType (lldb .eBasicTypeVoid ).GetPointerType ()
289
+ self .assertTrue (void_ptr )
290
+ # Not exactly guaranteed by the spec, but should be true everywhere we
291
+ # care about.
292
+ self .assertEqual (void_ptr .GetByteSize (), void_ptr .GetByteAlign ())
293
+
294
+ # And an over-aligned type.
295
+ self .assertEqual (module .FindFirstType ("OverAlignedStruct" ).GetByteAlign (), 128 )
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ enum EnumType {};
50
50
enum class ScopedEnumType {};
51
51
enum class EnumUChar : unsigned char {};
52
52
53
+ struct alignas (128 ) OverAlignedStruct {};
54
+ OverAlignedStruct over_aligned_struct;
55
+
53
56
int main (int argc, char const *argv[])
54
57
{
55
58
Task *task_head = new Task (-1 , NULL );
You can’t perform that action at this time.
0 commit comments