Skip to content

[rebranch] Various changes to get rebranch compiling #8938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/CodeGen/SwiftCallingConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class SwiftAggLowering {
/// passed indirectly as an argument
bool shouldPassIndirectly(bool asReturnValue) const;

bool shouldReturnTypedErrorIndirectly() const;

using EnumerationCallback =
llvm::function_ref<void(CharUnits offset, CharUnits end, llvm::Type *type)>;

Expand Down
1 change: 1 addition & 0 deletions clang/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Clang_Basic {
umbrella "clang/Basic"

textual header "clang/Basic/AArch64SVEACLETypes.def"
textual header "clang/Basic/AMDGPUTypes.def"
textual header "clang/Basic/BuiltinsAArch64.def"
textual header "clang/Basic/BuiltinsAMDGPU.def"
textual header "clang/Basic/BuiltinsAArch64NeonSVEBridge.def"
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/CodeGen/ABIInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ bool SwiftABIInfo::shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
return occupiesMoreThan(ComponentTys, /*total=*/4);
}

bool SwiftABIInfo::shouldReturnTypedErrorIndirectly(
ArrayRef<llvm::Type *> ComponentTys) const {
for (llvm::Type *type : ComponentTys) {
if (!type->isIntegerTy() && !type->isPointerTy())
return true;
}
return shouldPassIndirectly(ComponentTys, /*AsReturnValue=*/true);
}

bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
unsigned NumElts) const {
// The default implementation of this assumes that the target guarantees
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/ABIInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class SwiftABIInfo {

/// Returns true if swifterror is lowered to a register by the target ABI.
bool isSwiftErrorInRegister() const { return SwiftErrorInRegister; };

virtual bool
shouldReturnTypedErrorIndirectly(ArrayRef<llvm::Type *> ComponentTys) const;
};
} // end namespace CodeGen
} // end namespace clang
Expand Down
21 changes: 21 additions & 0 deletions clang/lib/CodeGen/SwiftCallingConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,27 @@ bool SwiftAggLowering::shouldPassIndirectly(bool asReturnValue) const {
return getSwiftABIInfo(CGM).shouldPassIndirectly(componentTys, asReturnValue);
}

bool SwiftAggLowering::shouldReturnTypedErrorIndirectly() const {
assert(Finished && "haven't yet finished lowering");

// Empty types don't need to be passed indirectly.
if (Entries.empty())
return false;

// Avoid copying the array of types when there's just a single element.
if (Entries.size() == 1) {
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(
Entries.back().Type);
}

SmallVector<llvm::Type *, 8> componentTys;
componentTys.reserve(Entries.size());
for (auto &entry : Entries) {
componentTys.push_back(entry.Type);
}
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(componentTys);
}

bool swiftcall::shouldPassIndirectly(CodeGenModule &CGM,
ArrayRef<llvm::Type*> componentTys,
bool asReturnValue) {
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Index/IndexRecordHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ static hash_code computeHash(const TemplateArgument &Arg,
case TemplateArgument::Integral:
COMBINE_HASH('V', Hasher.hash(Arg.getIntegralType()), Arg.getAsIntegral());
break;

case TemplateArgument::StructuralValue:
// FIXME: Hash structural values
break;
}

return Hash;
Expand Down
25 changes: 23 additions & 2 deletions lldb/include/lldb/Expression/ExpressionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,35 @@ class ExpressionParser {
/// \return
/// An error code indicating the success or failure of the operation.
/// Test with Success().
virtual Status
Status
PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
ExecutionContext &exe_ctx, bool &can_interpret,
lldb_private::ExecutionPolicy execution_policy) = 0;
lldb_private::ExecutionPolicy execution_policy);

bool GetGenerateDebugInfo() const { return m_generate_debug_info; }

protected:
virtual Status
DoPrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
ExecutionContext &exe_ctx, bool &can_interpret,
lldb_private::ExecutionPolicy execution_policy) = 0;

private:
/// Run all static initializers for an execution unit.
///
/// \param[in] execution_unit_sp
/// The execution unit.
///
/// \param[in] exe_ctx
/// The execution context to use when running them. Thread can't be null.
///
/// \return
/// The error code indicating the
Status RunStaticInitializers(lldb::IRExecutionUnitSP &execution_unit_sp,
ExecutionContext &exe_ctx);

protected:
Expression &m_expr; ///< The expression to be parsed
bool m_generate_debug_info;
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Expression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_lldb_library(lldbExpression ${PLUGIN_DEPENDENCY_ARG}
DWARFExpression.cpp
DWARFExpressionList.cpp
Expression.cpp
ExpressionParser.cpp
ExpressionTypeSystemHelper.cpp
ExpressionVariable.cpp
FunctionCaller.cpp
Expand Down
72 changes: 72 additions & 0 deletions lldb/source/Expression/ExpressionParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//===-- ExpressionParser.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Expression/ExpressionParser.h"
#include "lldb/Expression/DiagnosticManager.h"
#include "lldb/Expression/IRExecutionUnit.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/ThreadPlanCallFunction.h"

using namespace lldb;
using namespace lldb_private;

Status ExpressionParser::PrepareForExecution(
addr_t &func_addr, addr_t &func_end,
std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
ExecutionContext &exe_ctx, bool &can_interpret,
ExecutionPolicy execution_policy) {
Status status =
DoPrepareForExecution(func_addr, func_end, execution_unit_sp, exe_ctx,
can_interpret, execution_policy);
if (status.Success() && exe_ctx.GetProcessPtr() && exe_ctx.HasThreadScope())
status = RunStaticInitializers(execution_unit_sp, exe_ctx);

return status;
}

Status
ExpressionParser::RunStaticInitializers(IRExecutionUnitSP &execution_unit_sp,
ExecutionContext &exe_ctx) {
Status err;

if (!execution_unit_sp.get()) {
err.SetErrorString(
"can't run static initializers for a NULL execution unit");
return err;
}

if (!exe_ctx.HasThreadScope()) {
err.SetErrorString("can't run static initializers without a thread");
return err;
}

std::vector<addr_t> static_initializers;

execution_unit_sp->GetStaticInitializers(static_initializers);

for (addr_t static_initializer : static_initializers) {
EvaluateExpressionOptions options;

ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(
exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(),
llvm::ArrayRef<addr_t>(), options));

DiagnosticManager execution_errors;
ExpressionResults results =
exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(
exe_ctx, call_static_initializer, options, execution_errors);

if (results != eExpressionCompleted) {
err.SetErrorStringWithFormat("couldn't run static initializer: %s",
execution_errors.GetString().c_str());
return err;
}
}

return err;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ static bool FindFunctionInModule(ConstString &mangled_name,
return false;
}

lldb_private::Status ClangExpressionParser::PrepareForExecution(
lldb_private::Status ClangExpressionParser::DoPrepareForExecution(
lldb::addr_t &func_addr, lldb::addr_t &func_end,
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,
bool &can_interpret, ExecutionPolicy execution_policy) {
Expand Down Expand Up @@ -1472,47 +1472,3 @@ lldb_private::Status ClangExpressionParser::PrepareForExecution(

return err;
}

lldb_private::Status ClangExpressionParser::RunStaticInitializers(
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx) {
lldb_private::Status err;

lldbassert(execution_unit_sp.get());
lldbassert(exe_ctx.HasThreadScope());

if (!execution_unit_sp.get()) {
err.SetErrorString(
"can't run static initializers for a NULL execution unit");
return err;
}

if (!exe_ctx.HasThreadScope()) {
err.SetErrorString("can't run static initializers without a thread");
return err;
}

std::vector<lldb::addr_t> static_initializers;

execution_unit_sp->GetStaticInitializers(static_initializers);

for (lldb::addr_t static_initializer : static_initializers) {
EvaluateExpressionOptions options;

lldb::ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(
exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(),
llvm::ArrayRef<lldb::addr_t>(), options));

DiagnosticManager execution_errors;
lldb::ExpressionResults results =
exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(
exe_ctx, call_static_initializer, options, execution_errors);

if (results != lldb::eExpressionCompleted) {
err.SetErrorStringWithFormat("couldn't run static initializer: %s",
execution_errors.GetString().c_str());
return err;
}
}

return err;
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,11 @@ class ClangExpressionParser : public ExpressionParser {
/// \return
/// An error code indicating the success or failure of the operation.
/// Test with Success().
Status
PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
lldb::IRExecutionUnitSP &execution_unit_sp,
ExecutionContext &exe_ctx, bool &can_interpret,
lldb_private::ExecutionPolicy execution_policy) override;

/// Run all static initializers for an execution unit.
///
/// \param[in] execution_unit_sp
/// The execution unit.
///
/// \param[in] exe_ctx
/// The execution context to use when running them. Thread can't be null.
///
/// \return
/// The error code indicating the
Status RunStaticInitializers(lldb::IRExecutionUnitSP &execution_unit_sp,
ExecutionContext &exe_ctx);
Status DoPrepareForExecution(
lldb::addr_t &func_addr, lldb::addr_t &func_end,
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,
bool &can_interpret,
lldb_private::ExecutionPolicy execution_policy) override;

/// Returns a string representing current ABI.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,21 +698,6 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
if (!parse_success)
return false;

if (exe_ctx.GetProcessPtr() && execution_policy == eExecutionPolicyTopLevel) {
Status static_init_error =
m_parser->RunStaticInitializers(m_execution_unit_sp, exe_ctx);

if (!static_init_error.Success()) {
const char *error_cstr = static_init_error.AsCString();
if (error_cstr && error_cstr[0])
diagnostic_manager.Printf(lldb::eSeverityError, "%s\n", error_cstr);
else
diagnostic_manager.PutString(lldb::eSeverityError,
"couldn't run static initializers\n");
return false;
}
}

if (m_execution_unit_sp) {
bool register_execution_unit = false;

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class DWARFASTParserSwift : public lldb_private::plugin::dwarf::DWARFASTParser,
lldb_private::CompilerDeclContext decl_context) override {}

// FIXME: What should this do?
lldb_private::ConstString
std::string
GetDIEClassTemplateParams(const DWARFDIE &die) override {
assert(false && "DWARFASTParserSwift::GetDIEClassTemplateParams has not "
"yet been implemented");
return lldb_private::ConstString();
return {};
}

static bool classof(const DWARFASTParser *Parser) {
Expand Down
31 changes: 0 additions & 31 deletions lldb/source/Target/ThreadPlanStepOverRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,37 +334,6 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) {
return false;
}

bool ThreadPlanStepRange::DoPlanExplainsStop(Event *event_ptr) {
// For crashes, breakpoint hits, signals, etc,cd let the base plan (or some
// plan above us) handle the stop. That way the user can see the stop, step
// around, and then when they are done, continue and have their step
// complete. The exception is if we've hit our "run to next branch"
// breakpoint. Note, unlike the step in range plan, we don't mark ourselves
// complete if we hit an unexplained breakpoint/crash.

Log *log = GetLog(LLDBLog::Step);
StopInfoSP stop_info_sp = GetPrivateStopInfo();
bool return_value;

if (stop_info_sp) {
StopReason reason = stop_info_sp->GetStopReason();

if (reason == eStopReasonTrace) {
return_value = true;
} else if (reason == eStopReasonBreakpoint) {
return_value = NextRangeBreakpointExplainsStop(stop_info_sp);
} else {
if (log)
log->PutCString("ThreadPlanStepOverRange got asked if it explains the "
"stop for some reason other than step.");
return_value = false;
}
} else
return_value = true;

return return_value;
}

bool ThreadPlanStepOverRange::DoWillResume(lldb::StateType resume_state,
bool current_plan) {
if (resume_state != eStateSuspended && m_first_resume) {
Expand Down