Files
carbon-lang/toolchain/sem_ir/entry_point.cpp
T
Prabhat Sachdeva a5a4c756a7 Only treat top-level Run in Main as the entry point (#6757)
Fix IsEntryPoint to only recognize `Run` as the program entry point when
it is declared at package scope in the `Main` package, not when it
appears inside a namespace or via C++ interop.

Closes #6755
2026-02-18 22:17:15 +00:00

25 lines
815 B
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/sem_ir/entry_point.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::SemIR {
static constexpr llvm::StringLiteral EntryPointFunction = "Run";
auto IsEntryPoint(const File& file, FunctionId function_id) -> bool {
const auto& function = file.functions().Get(function_id);
return function.parent_scope_id == NameScopeId::Package &&
file.package_id() == PackageNameId::None &&
function.name_id.has_value() &&
file.names().GetAsStringIfIdentifier(function.name_id) ==
EntryPointFunction;
}
} // namespace Carbon::SemIR