diff options
author | Sean Callanan <scallanan@apple.com> | 2010-09-30 21:18:25 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2010-09-30 21:18:25 +0000 |
commit | 038df5031535ce23897d383755906401e1554554 (patch) | |
tree | 829d3eec11d9c070cf002cdd2497b5043b1ded90 /lldb/source/Expression/IRForTarget.cpp | |
parent | 748a5279b1a1d33bd77b9d57079e1f4823499905 (diff) | |
download | bcm5719-llvm-038df5031535ce23897d383755906401e1554554.tar.gz bcm5719-llvm-038df5031535ce23897d383755906401e1554554.zip |
Switched the expression parser from using TargetData
to using Clang to get type sizes. This fixes a bug
where the type size for a double[2] was being wrongly
reported as 8 instead of 16 bytes, causing problems
for IRForTarget.
Also improved logging so that the next bug in this
area will be easier to find.
llvm-svn: 115208
Diffstat (limited to 'lldb/source/Expression/IRForTarget.cpp')
-rw-r--r-- | lldb/source/Expression/IRForTarget.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp index 6ddd6c1d740..662c086373b 100644 --- a/lldb/source/Expression/IRForTarget.cpp +++ b/lldb/source/Expression/IRForTarget.cpp @@ -32,22 +32,20 @@ using namespace llvm; static char ID; IRForTarget::IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map, - const TargetData *target_data, bool resolve_vars, const char *func_name) : ModulePass(ID), m_decl_map(decl_map), - m_target_data(target_data), m_sel_registerName(NULL), m_func_name(func_name), m_resolve_vars(resolve_vars) { } -/* A handy utility function used at several places in the code */ +/* Handy utility functions used at several places in the code */ static std::string -PrintValue(Value *V, bool truncate = false) +PrintValue(const Value *V, bool truncate = false) { std::string s; raw_string_ostream rso(s); @@ -58,6 +56,18 @@ PrintValue(Value *V, bool truncate = false) return s; } +static std::string +PrintType(const Type *T, bool truncate = false) +{ + std::string s; + raw_string_ostream rso(s); + T->print(rso); + rso.flush(); + if (truncate) + s.resize(s.length() - 1); + return s; +} + IRForTarget::~IRForTarget() { } @@ -578,23 +588,34 @@ IRForTarget::MaybeHandleVariable(Module &M, std::string name = named_decl->getName().str(); - void *qual_type = NULL; + void *opaque_type = NULL; clang::ASTContext *ast_context = NULL; if (clang::ValueDecl *value_decl = dyn_cast<clang::ValueDecl>(named_decl)) { - qual_type = value_decl->getType().getAsOpaquePtr(); + opaque_type = value_decl->getType().getAsOpaquePtr(); ast_context = &value_decl->getASTContext(); } else { return false; } + + clang::QualType qual_type(clang::QualType::getFromOpaquePtr(opaque_type)); const Type *value_type = global_variable->getType(); - - size_t value_size = m_target_data->getTypeStoreSize(value_type); - off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type); + + size_t value_size = (ast_context->getTypeSize(qual_type) + 7) / 8; + off_t value_alignment = (ast_context->getTypeAlign(qual_type) + 7) / 8; + + if (log) + log->Printf("Type of %s is [clang %s, lldb %s] [size %d, align %d]", + name.c_str(), + qual_type.getAsString().c_str(), + PrintType(value_type).c_str(), + value_size, + value_alignment); + if (named_decl && !m_decl_map->AddValueToStruct(named_decl, name.c_str(), @@ -1103,6 +1124,13 @@ IRForTarget::runOnModule(Module &M) return false; } + /////////////////////////////// + // Run function-level passes + // + + if (!replaceVariables(M, *function)) + return false; + if (log) { std::string s; @@ -1115,13 +1143,6 @@ IRForTarget::runOnModule(Module &M) log->Printf("Module after preparing for execution: \n%s", s.c_str()); } - /////////////////////////////// - // Run function-level passes - // - - if (!replaceVariables(M, *function)) - return false; - return true; } |