Skip to content

Commit 36f13e4

Browse files
committed
[Symbol] GetTypeBitAlign() should return None in case of failure.
Summary: And not `zero`. This is the last API needed to be converted to an Optional<T>. Reviewers: xiaobai, compnerd Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D66093 llvm-svn: 368614
1 parent d2e493c commit 36f13e4

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

lldb/include/lldb/Symbol/ClangASTContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ class ClangASTContext : public TypeSystem {
708708

709709
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
710710

711-
size_t GetTypeBitAlign(lldb::opaque_compiler_type_t type) override;
711+
llvm::Optional<size_t>
712+
GetTypeBitAlign(lldb::opaque_compiler_type_t type) override;
712713

713714
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
714715
bool omit_empty_base_classes,

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class CompilerType {
257257

258258
lldb::Format GetFormat() const;
259259

260-
size_t GetTypeBitAlign() const;
260+
llvm::Optional<size_t> GetTypeBitAlign() const;
261261

262262
uint32_t GetNumChildren(bool omit_empty_base_classes,
263263
const ExecutionContext *exe_ctx) const;

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ class TypeSystem : public PluginInterface {
386386
virtual bool IsCStringType(lldb::opaque_compiler_type_t type,
387387
uint32_t &length) = 0;
388388

389-
virtual size_t GetTypeBitAlign(lldb::opaque_compiler_type_t type) = 0;
389+
virtual llvm::Optional<size_t>
390+
GetTypeBitAlign(lldb::opaque_compiler_type_t type) = 0;
390391

391392
virtual CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) = 0;
392393

lldb/source/Expression/Materializer.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,15 @@ class EntityVariable : public Materializer::Entity {
530530
return;
531531
}
532532

533-
size_t bit_align =
533+
llvm::Optional<size_t> opt_bit_align =
534534
m_variable_sp->GetType()->GetLayoutCompilerType().GetTypeBitAlign();
535-
size_t byte_align = (bit_align + 7) / 8;
535+
if (!opt_bit_align) {
536+
err.SetErrorStringWithFormat("can't get the type alignment for %s",
537+
m_variable_sp->GetName().AsCString());
538+
return;
539+
}
536540

537-
if (!byte_align)
538-
byte_align = 1;
541+
size_t byte_align = (*opt_bit_align + 7) / 8;
539542

540543
Status alloc_error;
541544
const bool zero_memory = false;
@@ -788,11 +791,14 @@ class EntityResultVariable : public Materializer::Entity {
788791
err.SetErrorString("can't get size of type");
789792
return;
790793
}
791-
size_t bit_align = m_type.GetTypeBitAlign();
792-
size_t byte_align = (bit_align + 7) / 8;
793794

794-
if (!byte_align)
795-
byte_align = 1;
795+
llvm::Optional<size_t> opt_bit_align = m_type.GetTypeBitAlign();
796+
if (!opt_bit_align) {
797+
err.SetErrorStringWithFormat("can't get the type alignment");
798+
return;
799+
}
800+
801+
size_t byte_align = (*opt_bit_align + 7) / 8;
796802

797803
Status alloc_error;
798804
const bool zero_memory = true;

lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,10 @@ bool IRForTarget::MaybeHandleVariable(Value *llvm_value_ptr) {
13021302
llvm::Optional<uint64_t> value_size = compiler_type.GetByteSize(nullptr);
13031303
if (!value_size)
13041304
return false;
1305-
lldb::offset_t value_alignment =
1306-
(compiler_type.GetTypeBitAlign() + 7ull) / 8ull;
1305+
llvm::Optional<size_t> opt_alignment = compiler_type.GetTypeBitAlign();
1306+
if (!opt_alignment)
1307+
return false;
1308+
lldb::offset_t value_alignment = (*opt_alignment + 7ull) / 8ull;
13071309

13081310
LLDB_LOG(log,
13091311
"Type of \"{0}\" is [clang \"{1}\", llvm \"{2}\"] [size {3}, "

lldb/source/Symbol/ClangASTContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5087,10 +5087,11 @@ ClangASTContext::GetBitSize(lldb::opaque_compiler_type_t type,
50875087
return None;
50885088
}
50895089

5090-
size_t ClangASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type) {
5090+
llvm::Optional<size_t>
5091+
ClangASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type) {
50915092
if (GetCompleteType(type))
50925093
return getASTContext()->getTypeAlign(GetQualType(type));
5093-
return 0;
5094+
return {};
50945095
}
50955096

50965097
lldb::Encoding ClangASTContext::GetEncoding(lldb::opaque_compiler_type_t type,

lldb/source/Symbol/CompilerType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,10 @@ CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const {
503503
return {};
504504
}
505505

506-
size_t CompilerType::GetTypeBitAlign() const {
506+
llvm::Optional<size_t> CompilerType::GetTypeBitAlign() const {
507507
if (IsValid())
508508
return m_type_system->GetTypeBitAlign(m_type);
509-
return 0;
509+
return {};
510510
}
511511

512512
lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const {

0 commit comments

Comments
 (0)