diff --git a/bazel/carbon_rules/defs.bzl b/bazel/carbon_rules/defs.bzl index ef52903bb076..b1a4f8b36dd2 100644 --- a/bazel/carbon_rules/defs.bzl +++ b/bazel/carbon_rules/defs.bzl @@ -4,6 +4,7 @@ """Provides rules for building Carbon files using the toolchain.""" +load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") @@ -26,8 +27,10 @@ def _carbon_binary_impl(ctx): # Pass any C++ flags from our dependencies onto Carbon. dep_flags = [] dep_hdrs = [] + dep_api_files = [] dep_link_inputs = [] - for dep in ctx.attr.deps: + deps = ctx.attr.deps + ctx.attr._default_deps + for dep in deps: if CcInfo in dep: cc_info = dep[CcInfo] @@ -46,16 +49,16 @@ def _carbon_binary_impl(ctx): dep_link_inputs += lib.objects if DefaultInfo in dep: dep_link_inputs += dep[DefaultInfo].files.to_list() + if CarbonLibraryInfo in dep: + carbon_info = dep[CarbonLibraryInfo] + dep_link_inputs += carbon_info.objs.to_list() + dep_api_files.append(carbon_info.api) # Add the dependencies' link flags and inputs to the link flags. link_flags += [dep.path for dep in dep_link_inputs] # Build object files for the prelude and for the binary itself. - # TODO: Eventually the prelude should be build as a separate `carbon_library`. - srcs_and_flags = [ - (ctx.files.prelude_srcs, ["--no-prelude-import"]), - (ctx.files.srcs, dep_flags), - ] + srcs_and_flags = [(ctx.files.srcs, dep_flags)] objs = [] for (srcs, extra_flags) in srcs_and_flags: @@ -76,13 +79,14 @@ def _carbon_binary_impl(ctx): src.short_path.removeprefix(ctx.label.package).removesuffix(src.extension), )) objs.append(out) - srcs_reordered = [s for s in srcs if s != src] + [src] + srcs_reordered = dep_api_files + [s for s in srcs if s != src] + [src] ctx.actions.run( outputs = [out], inputs = depset(direct = srcs_reordered, transitive = dep_hdrs), executable = toolchain_driver, tools = depset(toolchain_data), arguments = ["compile", "--output=" + out.path, "--output-last-input-only"] + + ["--no-include-carbon-core"] + [s.path for s in srcs_reordered] + extra_flags + ctx.attr.flags, mnemonic = "CarbonCompile", progress_message = "Compiling " + src.short_path, @@ -119,19 +123,164 @@ def _carbon_binary_impl(ctx): ctx.actions.run( outputs = [bin], - inputs = objs + dep_link_inputs, + inputs = depset(direct = objs + dep_link_inputs), executable = toolchain_driver, - tools = depset(toolchain_data + prebuilt_runtimes), + tools = depset(direct = toolchain_data + prebuilt_runtimes), arguments = full_link_flags, mnemonic = "CarbonLink", progress_message = "Linking " + bin.short_path, ) return [DefaultInfo(files = depset([bin]), executable = bin)] +CarbonLibraryInfo = provider( + doc = "Contains information about a compiled Carbon library.", + fields = { + "api": "The api source file to provide to library consumers.", + "objs": "A depset of one or more compiled library files, including impl and api.", + }, +) + +def _carbon_library_impl(ctx): + toolchain_driver = ctx.executable.internal_exec_toolchain_driver + toolchain_data = ctx.files.internal_exec_toolchain_data + + # If the exec driver isn't provided, that means we're trying to use a target + # config toolchain, likely to avoid build overhead of two configs. + if toolchain_driver == None: + toolchain_driver = ctx.executable.internal_target_toolchain_driver + toolchain_data = ctx.files.internal_target_toolchain_data + + # Pass any C++ flags from our dependencies onto Carbon. + dep_flags = [] + dep_hdrs = [] + dep_api_srcs = [] + for dep in ctx.attr.deps: + if CcInfo in dep: + cc_info = dep[CcInfo] + + # TODO: We should reuse the feature-based flag generation in + # bazel/cc_toolchains here. + dep_flags += ["--clang-arg=-D{0}".format(define) for define in cc_info.compilation_context.defines.to_list()] + dep_flags += ["--clang-arg=-I{0}".format(path) for path in cc_info.compilation_context.includes.to_list()] + dep_flags += ["--clang-arg=-iquote{0}".format(path) for path in cc_info.compilation_context.quote_includes.to_list()] + dep_flags += ["--clang-arg=-isystem{0}".format(path) for path in cc_info.compilation_context.system_includes.to_list()] + dep_hdrs.append(cc_info.compilation_context.headers) + if CarbonLibraryInfo in dep: + carbon_info = dep[CarbonLibraryInfo] + dep_api_srcs.append(carbon_info.api) + + # Build object files for the library impls and api file + srcs_and_flags = [(ctx.files.impls + ctx.files.api, dep_flags)] + + objs = [] + for (srcs, extra_flags) in srcs_and_flags: + for src in srcs: + # Build each source file. For now, we pass all sources to each compile + # because we don't have visibility into dependencies and have no way to + # specify multiple output files. Object code for each input is written + # into the output file in turn, so the final carbon source file + # specified ends up determining the contents of the object file. + # + # TODO: This is a hack; replace with something better once the toolchain + # supports doing so. + # + # TODO: Switch to the `prefix` based rule similar to linking when + # the prelude moves there. + out = ctx.actions.declare_file("_objs/{0}/{1}o".format( + ctx.label.name, + src.short_path.removeprefix(ctx.label.package).removesuffix(src.extension), + )) + objs.append(out) + srcs_reordered = dep_api_srcs + [s for s in srcs if s != src] + [src] + ctx.actions.run( + outputs = [out], + inputs = depset(direct = srcs_reordered, transitive = dep_hdrs), + executable = toolchain_driver, + tools = depset(toolchain_data), + arguments = ["compile", "--output=" + out.path, "--output-last-input-only"] + + ["--no-include-carbon-core"] + + extra_flags + ctx.attr.flags + [s.path for s in srcs_reordered], + mnemonic = "CarbonCompile", + progress_message = "Compiling " + src.short_path, + ) + + return [CarbonLibraryInfo(api = ctx.files.api[0], objs = depset(objs))] + +def _carbon_prelude_impl(ctx): + cc_toolchain = find_cpp_toolchain(ctx) + + # TODO: find a less terrible way to figure this out + repo_root = str(cc_toolchain.compiler_executable) + repo_root = repo_root.removeprefix(cc_toolchain._crosstool_top_path + "/") + + # The tool path seems to be relative to the toolchain _repository_ root, so + # it includes the `toolchain/install` suffix, which is why we remove it here. + repo_root = repo_root.removesuffix("toolchain/install/llvm/bin/clang++") + + carbon_busybox = repo_root + cc_toolchain._tool_paths["carbon-busybox"] + + srcs = [s for s in ctx.files.srcs if s.extension == "carbon"] + objs = [] + for src in srcs: + out = ctx.actions.declare_file("_objs/{0}/{1}o".format( + ctx.label.name, + src.short_path.removeprefix(ctx.label.package).removesuffix(src.extension), + )) + objs.append(out) + srcs_reordered = [s for s in srcs if s != src] + [src] + ctx.actions.run( + outputs = [out], + inputs = depset(direct = srcs_reordered), + tools = depset(transitive = [cc_toolchain.all_files]), + executable = carbon_busybox, + arguments = ["compile", "--output=" + out.path, "--output-last-input-only"] + + ["--no-prelude-import"] + + [s.path for s in srcs_reordered] + ctx.attr.flags, + mnemonic = "CarbonPrelude", + progress_message = "Precompiling prelude file " + src.short_path, + ) + + return DefaultInfo(files = depset(objs)) + +# We synthesize two sets of attributes from mirrored `select`s here +# because we want to select on an internal property of these attributes +# but that isn't `select`-able. Instead, we have both attributes and +# `select` which one we use. +_select_internal_exec_toolchain_driver = select({ + Label("//bazel/carbon_rules:use_target_config_carbon_rules_config"): None, + "//conditions:default": Label("//toolchain/install:carbon-busybox"), +}) +_select_internal_exec_toolchain_data = select({ + Label("//bazel/carbon_rules:use_target_config_carbon_rules_config"): None, + "//conditions:default": Label("//toolchain/install:install_data"), +}) +_select_internal_exec_prebuilt_runtimes = select({ + Label("//bazel/carbon_rules:use_target_config_carbon_rules_config"): None, + "//conditions:default": Label("//toolchain/install:built_runtimes"), +}) +_select_internal_target_toolchain_driver = select({ + Label( + "//bazel/carbon_rules:use_target_config_carbon_rules_config", + ): Label("//toolchain/install:carbon-busybox"), + "//conditions:default": None, +}) +_select_internal_target_toolchain_data = select({ + Label( + "//bazel/carbon_rules:use_target_config_carbon_rules_config", + ): Label("//toolchain/install:install_data"), + "//conditions:default": None, +}) +_select_internal_target_prebuilt_runtimes = select({ + Label( + "//bazel/carbon_rules:use_target_config_carbon_rules_config", + ): Label("//toolchain/install:built_runtimes"), + "//conditions:default": None, +}) + _carbon_binary_internal = rule( implementation = _carbon_binary_impl, attrs = { - "deps": attr.label_list(allow_files = True, providers = [[CcInfo]]), + "deps": attr.label_list(allow_files = True, providers = [[CcInfo], [CarbonLibraryInfo]]), "flags": attr.string_list(), # The exec config toolchain attributes. These will be `None` when using @@ -167,14 +316,74 @@ _carbon_binary_internal = rule( executable = True, cfg = "target", ), - "prelude_srcs": attr.label_list(allow_files = [".carbon"]), "srcs": attr.label_list(allow_files = [".carbon"]), "_cc_toolchain": attr.label(default = "//toolchain/install:carbon_stage1_cc_toolchain"), + "_default_deps": attr.label_list(default = [Label("//core:io"), Label("//core:range")]), }, executable = True, fragments = ["cpp"], ) +_carbon_library_internal = rule( + implementation = _carbon_library_impl, + attrs = { + "api": attr.label(allow_single_file = True), + "deps": attr.label_list(allow_files = True), + "flags": attr.string_list(), + "impls": attr.label_list(allow_files = [".carbon"]), + + # The exec config toolchain attributes. These will be `None` when using + # the target config and populated when using the exec config. We have to + # use duplicate attributes here and below to have different `cfg` + # settings, as that isn't `select`-able, and we'll use `select`s when + # populating these. + "internal_exec_prebuilt_runtimes": attr.label( + cfg = "exec", + ), + "internal_exec_toolchain_data": attr.label( + cfg = "exec", + ), + "internal_exec_toolchain_driver": attr.label( + allow_single_file = True, + executable = True, + cfg = "exec", + ), + + # The target config toolchain attributes. These will be 'None' when + # using the exec config and populated when using the target config. We + # have to use duplicate attributes here and below to have different + # `cfg` settings, as that isn't `select`-able, and we'll use `select`s + # when populating these. + "internal_target_prebuilt_runtimes": attr.label( + cfg = "target", + ), + "internal_target_toolchain_data": attr.label( + cfg = "target", + ), + "internal_target_toolchain_driver": attr.label( + allow_single_file = True, + executable = True, + cfg = "target", + ), + "_cc_toolchain": attr.label(default = "//toolchain/install:carbon_stage1_cc_toolchain"), + }, + executable = False, + fragments = ["cpp"], +) + +carbon_prelude = rule( + implementation = _carbon_prelude_impl, + attrs = { + "flags": attr.string_list(), + "srcs": attr.label_list(allow_files = [".carbon"]), + "_cc_toolchain": attr.label( + default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), + ), + }, + toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], + fragments = ["cpp"], +) + def carbon_binary(name, srcs, deps = [], flags = [], tags = []): """Compiles a Carbon binary. @@ -188,43 +397,41 @@ def carbon_binary(name, srcs, deps = [], flags = [], tags = []): _carbon_binary_internal( name = name, srcs = srcs, - prelude_srcs = [Label("//core:prelude_files")], deps = deps, flags = flags, tags = tags, + internal_exec_toolchain_driver = _select_internal_exec_toolchain_driver, + internal_exec_toolchain_data = _select_internal_exec_toolchain_data, + internal_exec_prebuilt_runtimes = _select_internal_exec_prebuilt_runtimes, + internal_target_toolchain_driver = _select_internal_target_toolchain_driver, + internal_target_toolchain_data = _select_internal_target_toolchain_data, + internal_target_prebuilt_runtimes = _select_internal_target_prebuilt_runtimes, + ) - # We synthesize two sets of attributes from mirrored `select`s here - # because we want to select on an internal property of these attributes - # but that isn't `select`-able. Instead, we have both attributes and - # `select` which one we use. - internal_exec_toolchain_driver = select({ - Label("//bazel/carbon_rules:use_target_config_carbon_rules_config"): None, - "//conditions:default": Label("//toolchain/install:carbon-busybox"), - }), - internal_exec_toolchain_data = select({ - Label("//bazel/carbon_rules:use_target_config_carbon_rules_config"): None, - "//conditions:default": Label("//toolchain/install:install_data"), - }), - internal_exec_prebuilt_runtimes = select({ - Label("//bazel/carbon_rules:use_target_config_carbon_rules_config"): None, - "//conditions:default": Label("//toolchain/install:built_runtimes"), - }), - internal_target_toolchain_driver = select({ - Label( - "//bazel/carbon_rules:use_target_config_carbon_rules_config", - ): Label("//toolchain/install:carbon-busybox"), - "//conditions:default": None, - }), - internal_target_toolchain_data = select({ - Label( - "//bazel/carbon_rules:use_target_config_carbon_rules_config", - ): Label("//toolchain/install:install_data"), - "//conditions:default": None, - }), - internal_target_prebuilt_runtimes = select({ - Label( - "//bazel/carbon_rules:use_target_config_carbon_rules_config", - ): Label("//toolchain/install:built_runtimes"), - "//conditions:default": None, - }), +def carbon_library(name, api, impls = [], deps = [], flags = [], tags = [], visibility = []): + """Compiles a Carbon library. + + Args: + name: The name of the build target. + api: Name of a single api file. + impls: List of zero or more implementation files. + deps: List of dependencies. + flags: Extra flags to pass to the Carbon compile command. + tags: Tags to apply to the rule. + visibility: Visibility rules for the library. + """ + _carbon_library_internal( + name = name, + api = api, + impls = impls, + deps = deps, + flags = flags, + tags = tags, + visibility = visibility, + internal_exec_toolchain_driver = _select_internal_exec_toolchain_driver, + internal_exec_toolchain_data = _select_internal_exec_toolchain_data, + internal_exec_prebuilt_runtimes = _select_internal_exec_prebuilt_runtimes, + internal_target_toolchain_driver = _select_internal_target_toolchain_driver, + internal_target_toolchain_data = _select_internal_target_toolchain_data, + internal_target_prebuilt_runtimes = _select_internal_target_prebuilt_runtimes, ) diff --git a/bazel/cc_toolchains/carbon_cc_toolchain_config.bzl b/bazel/cc_toolchains/carbon_cc_toolchain_config.bzl index 7ad1c1f41004..4061c66c90b5 100644 --- a/bazel/cc_toolchains/carbon_cc_toolchain_config.bzl +++ b/bazel/cc_toolchains/carbon_cc_toolchain_config.bzl @@ -11,6 +11,7 @@ load( "flag_group", "flag_set", "tool", + "tool_path", ) load( "@rules_cc//cc:defs.bzl", @@ -162,6 +163,7 @@ def _carbon_cc_toolchain_config_impl(ctx): ctx.attr.target_cpu, ctx.attr.target_os, ) + return cc_common.create_cc_toolchain_config_info( ctx = ctx, features = clang_cc_toolchain_features( @@ -197,7 +199,7 @@ def _carbon_cc_toolchain_config_impl(ctx): # Pass in our tool paths to expose Make variables like $(NM) and # $(OBJCOPY). - tool_paths = llvm_tool_paths(llvm_bindir, clang_bindir), + tool_paths = llvm_tool_paths(llvm_bindir, clang_bindir) + [tool_path(name = "carbon-busybox", path = "carbon-busybox")], ) carbon_cc_toolchain_config = rule( diff --git a/core/BUILD b/core/BUILD index 207f5f537f4e..d3d62a1bd7e1 100644 --- a/core/BUILD +++ b/core/BUILD @@ -2,13 +2,13 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("//bazel/carbon_rules:defs.bzl", "carbon_library") load("//bazel/manifest:defs.bzl", "manifest") # Raw prelude files. -# TODO: This includes all of Core, not just the prelude. filegroup( name = "prelude_files", - srcs = glob(["**/*.carbon"]), + srcs = ["prelude.carbon"] + glob(["prelude/**/*.carbon"]), visibility = ["//visibility:public"], ) @@ -29,3 +29,43 @@ filegroup( ], visibility = ["//visibility:public"], ) + +filegroup( + name = "core_library_files", + srcs = glob( + include = ["**/*.carbon"], + exclude = [ + "prelude.carbon", + "prelude/**", + ], + ), + visibility = ["//visibility:public"], +) + +manifest( + name = "core_library_manifest.txt", + srcs = [":core_library_files"], + strip_package_dir = True, +) + +filegroup( + name = "core_library", + srcs = [ + ":core_library_files", + ":core_library_manifest.txt", + ], + visibility = ["//visibility:public"], +) + +carbon_library( + name = "io", + api = "io.carbon", + impls = ["io.impl.carbon"], + visibility = ["//visibility:public"], +) + +carbon_library( + name = "range", + api = "range.carbon", + visibility = ["//visibility:public"], +) diff --git a/core/io.carbon b/core/io.carbon index 8a916d06b029..fff6cfe806f0 100644 --- a/core/io.carbon +++ b/core/io.carbon @@ -7,24 +7,15 @@ package Core library "io"; -import library "prelude"; - // TODO: Support printing other types. // TODO: Consider rewriting using native support once library support exists. fn Print(x: i32) = "print.int"; fn PrintChar(x: char) -> i32 = "print.char"; -fn PrintStr(msg: str) { - let size: i64 = msg.Size() as i64; - var i: i64 = 0; - while (i < size) { - PrintChar(msg[i]); - ++i; - } -} +fn PrintStr(msg: str); // TODO: Return an `Optional(char)` instead of `i32`. fn ReadChar() -> i32 = "read.char"; // TODO: Change this to a global constant once they are fully supported. -fn EOF() -> i32 { return -1; } +fn EOF() -> i32; diff --git a/core/io.impl.carbon b/core/io.impl.carbon new file mode 100644 index 000000000000..99faa0b96d3a --- /dev/null +++ b/core/io.impl.carbon @@ -0,0 +1,20 @@ +// 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 + +// TODO: This library is not part of the design. Either write a matching +// proposal or remove this. + +impl package Core library "io"; + +fn PrintStr(msg: str) { + let size: i64 = msg.Size() as i64; + var i: i64 = 0; + while (i < size) { + PrintChar(msg[i]); + ++i; + } +} + +// TODO: Change this to a global constant once they are fully supported. +fn EOF() -> i32 { return -1; } diff --git a/core/range.carbon b/core/range.carbon index 55b9de15eef4..299f83267307 100644 --- a/core/range.carbon +++ b/core/range.carbon @@ -7,15 +7,6 @@ package Core library "range"; -import library "prelude/destroy"; -import library "prelude/iterate"; -import library "prelude/operators/arithmetic"; -import library "prelude/operators/as"; -import library "prelude/operators/comparison"; -import library "prelude/types/int"; -import library "prelude/types/int_literal"; -import library "prelude/types/optional"; - class IntRange(N: IntLiteral) { fn Make(start: Int(N), end: Int(N)) -> Self { return {.start = start, .end = end}; diff --git a/toolchain/base/install_paths.cpp b/toolchain/base/install_paths.cpp index 130eee603032..9689be526a49 100644 --- a/toolchain/base/install_paths.cpp +++ b/toolchain/base/install_paths.cpp @@ -86,6 +86,11 @@ auto InstallPaths::ReadClangHeadersManifest() const return ReadManifest(root_, "clang_headers_manifest.txt"); } +auto InstallPaths::ReadCarbonCoreManifest() const + -> ErrorOr> { + return ReadManifest(core_package(), "core_library_manifest.txt"); +} + auto InstallPaths::ReadManifest(std::filesystem::path manifest_path, std::filesystem::path manifest_file) const -> ErrorOr> { diff --git a/toolchain/base/install_paths.h b/toolchain/base/install_paths.h index efb73830dfd4..1a225654d520 100644 --- a/toolchain/base/install_paths.h +++ b/toolchain/base/install_paths.h @@ -81,6 +81,11 @@ class InstallPaths { auto ReadClangHeadersManifest() const -> ErrorOr>; + // Returns the contents of the core library manifest file. This is the list + // of Carbon source files in the Carbon Core library, excluding the prelude. + auto ReadCarbonCoreManifest() const + -> ErrorOr>; + // Check for an error detecting the install paths correctly. // // A nullopt return means no errors encountered and the paths should work diff --git a/toolchain/base/runtimes_build_info.bzl b/toolchain/base/runtimes_build_info.bzl index 06501ed84e5a..44dc46f1bc44 100644 --- a/toolchain/base/runtimes_build_info.bzl +++ b/toolchain/base/runtimes_build_info.bzl @@ -25,6 +25,10 @@ load("@llvm-project//libcxx:libcxx_library.bzl", "libcxx_and_abi_copts") load("@llvm-project//libunwind:libunwind_library.bzl", "libunwind_copts") load("//bazel/cc_rules:defs.bzl", "cc_library") +CARBON_CORE_SRCS_FILEGROUPS = [ + "//core:prelude_files", +] + CRT_FILES = { "crtbegin_src": "@llvm-project//compiler-rt:builtins_crtbegin_src", "crtend_src": "@llvm-project//compiler-rt:builtins_crtend_src", @@ -72,6 +76,7 @@ RUNTIMES_PREFIXES = { "libcxxabi_textual_srcs": "runtimes/libcxxabi/", "libunwind_hdrs": "runtimes/libunwind/", "libunwind_srcs": "runtimes/libunwind/", + "prelude_files": "core/", } def _get_name(target): @@ -143,6 +148,7 @@ def _get_substitutions(ctx): RUNTIMES_PREFIXES[name], ) for name in [_get_name(g) for g in ( + CARBON_CORE_SRCS_FILEGROUPS + RUNTIMES_HDRS_FILEGROUPS + RUNTIMES_SRCS_FILEGROUPS + RUNTIMES_TEXTUAL_SRCS_FILEGROUPS )] @@ -154,6 +160,7 @@ _common_runtimes_rule_attrs = { } | { "_" + _get_name(g): attr.label_list(default = [g], allow_files = True) for g in ( + CARBON_CORE_SRCS_FILEGROUPS + BUILTINS_SRCS_FILEGROUPS + BUILTINS_TEXTUAL_SRCS_FILEGROUPS + RUNTIMES_HDRS_FILEGROUPS + diff --git a/toolchain/base/runtimes_build_info.tpl.h b/toolchain/base/runtimes_build_info.tpl.h index 10203f2e8b25..0f543400f0e0 100644 --- a/toolchain/base/runtimes_build_info.tpl.h +++ b/toolchain/base/runtimes_build_info.tpl.h @@ -40,6 +40,8 @@ inline constexpr llvm::StringLiteral LibcxxCopts[] = {LIBCXX_AND_ABI_COPTS}; inline constexpr llvm::StringLiteral LibunwindSrcs[] = {LIBUNWIND_SRCS}; inline constexpr llvm::StringLiteral LibunwindCopts[] = {LIBUNWIND_COPTS}; +inline constexpr llvm::StringLiteral CarbonCorePreludeSrcs[] = {PRELUDE_FILES}; + } // namespace Carbon::RuntimesBuildInfo #endif // CARBON_TOOLCHAIN_BASE_RUNTIMES_BUILD_INFO_TPL_H_ diff --git a/toolchain/base/runtimes_build_vars.tpl.bzl b/toolchain/base/runtimes_build_vars.tpl.bzl index f94e0d34d406..1ee14ef515fc 100644 --- a/toolchain/base/runtimes_build_vars.tpl.bzl +++ b/toolchain/base/runtimes_build_vars.tpl.bzl @@ -43,3 +43,5 @@ libunwind_hdrs = [LIBUNWIND_HDRS] libunwind_srcs = [LIBUNWIND_SRCS] libunwind_copts = [LIBUNWIND_COPTS] + +carbon_core_srcs = [PRELUDE_FILES] diff --git a/toolchain/benchmarking/compile_benchmark.cpp b/toolchain/benchmarking/compile_benchmark.cpp index 878f7487f54e..5890607de483 100644 --- a/toolchain/benchmarking/compile_benchmark.cpp +++ b/toolchain/benchmarking/compile_benchmark.cpp @@ -116,7 +116,9 @@ class InProcessCompiler { auto RunCompile(llvm::StringRef file_name, Phase phase) -> bool { if constexpr (L == Lang::Carbon) { - return driver_->RunCommand({"compile", PhaseFlag(phase), file_name}) + return driver_ + ->RunCommand({"compile", PhaseFlag(phase), "--no-include-carbon-core", + file_name}) .success; } @@ -204,7 +206,8 @@ class SubprocessCompiler { if constexpr (L == Lang::Carbon) { program = carbon_path_; - args = {"carbon", "compile", PhaseFlag(phase), file_name}; + args = {"carbon", "compile", PhaseFlag(phase), "--no-include-carbon-core", + file_name}; } else { program = clang_path_; args = {"clang++", "--driver-mode=g++"}; diff --git a/toolchain/benchmarking/prelude_benchmark.cpp b/toolchain/benchmarking/prelude_benchmark.cpp index 44625a1922cc..ebfe589e59d5 100644 --- a/toolchain/benchmarking/prelude_benchmark.cpp +++ b/toolchain/benchmarking/prelude_benchmark.cpp @@ -102,7 +102,9 @@ class PreludeCompileBenchmark { if (mem_usage) { driver.set_mem_usage(mem_usage); } - return driver.RunCommand({"compile", "--phase=check", InputFileName}) + return driver + .RunCommand({"compile", "--phase=check", "--no-include-carbon-core", + InputFileName}) .success; } diff --git a/toolchain/benchmarking/source_gen_test.cpp b/toolchain/benchmarking/source_gen_test.cpp index f73c104f2692..b98b9f37421c 100644 --- a/toolchain/benchmarking/source_gen_test.cpp +++ b/toolchain/benchmarking/source_gen_test.cpp @@ -242,7 +242,10 @@ auto TestCompile(llvm::StringRef source) -> bool { fs->addFile("test.carbon", /*ModificationTime=*/0, llvm::MemoryBuffer::getMemBuffer(source)); - return driver.RunCommand({"compile", "--phase=check", "test.carbon"}).success; + return driver + .RunCommand({"compile", "--phase=check", "--no-include-carbon-core", + "test.carbon"}) + .success; } TEST(SourceGenTest, GenApiFileDenseDeclsTest) { diff --git a/toolchain/check/check.cpp b/toolchain/check/check.cpp index a52f32aab27c..9f236caadd16 100644 --- a/toolchain/check/check.cpp +++ b/toolchain/check/check.cpp @@ -458,13 +458,25 @@ auto CheckParseTrees( // Add the prelude import. It's added to explicit_import_map so that it can // conflict with an explicit import of the prelude. + // We add the prelude to every Carbon unit except for the prelude itself. if (options.prelude_import && - !(packaging && packaging->names.package_id == PackageNameId::Core)) { + (!packaging || packaging->names.package_id != PackageNameId::Core || + packaging->names.library_id == StringLiteralValueId::None || + !unit_info.unit->value_stores->string_literal_values() + .Get(packaging->names.library_id) + .starts_with("prelude"))) { auto prelude_id = unit_info.unit->value_stores->string_literal_values().Add("prelude"); + // Adding the prelude to the non-prelude parts of Core requires different + // semantics because it is not valid to mention the name of the package + // for a library import from the same package. + auto package_id = + (packaging && packaging->names.package_id == PackageNameId::Core) + ? PackageNameId::None + : PackageNameId::Core; TrackImport(api_map, &explicit_import_map, unit_info, {.node_id = Parse::NoneNodeId(), - .package_id = PackageNameId::Core, + .package_id = package_id, .library_id = prelude_id}, options.fuzzing); } diff --git a/toolchain/check/testdata/basics/verbose.carbon b/toolchain/check/testdata/basics/verbose.carbon index 55343d8e964f..16632e50d276 100644 --- a/toolchain/check/testdata/basics/verbose.carbon +++ b/toolchain/check/testdata/basics/verbose.carbon @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon -// ARGS: -v compile --phase=check %s +// ARGS: -v compile --phase=check --no-include-carbon-core %s // // Only checks a couple statements in order to minimize manual update churn. // To test this file alone, run: diff --git a/toolchain/check/testdata/builtins/print/char.carbon b/toolchain/check/testdata/builtins/print/char.carbon index 3840357d68e1..733095e3350a 100644 --- a/toolchain/check/testdata/builtins/print/char.carbon +++ b/toolchain/check/testdata/builtins/print/char.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -29,7 +30,7 @@ fn Main() { // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete] // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete] // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] -// CHECK:STDOUT: %PrintChar.type.7a7: type = fn_type @PrintChar.loc15 [concrete] +// CHECK:STDOUT: %PrintChar.type.7a7: type = fn_type @PrintChar.loc16 [concrete] // CHECK:STDOUT: %PrintChar.772: %PrintChar.type.7a7 = struct_value () [concrete] // CHECK:STDOUT: %.75c: Core.CharLiteral = char_value U+0031 [concrete] // CHECK:STDOUT: %ImplicitAs.type.0ff: type = generic_interface_type @ImplicitAs [concrete] @@ -70,23 +71,23 @@ fn Main() { // CHECK:STDOUT: // CHECK:STDOUT: fn @Main() { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: %PrintChar.ref.loc19: %PrintChar.type.7a7 = name_ref PrintChar, file.%PrintChar.decl [concrete = constants.%PrintChar.772] -// CHECK:STDOUT: %.loc19_13.1: Core.CharLiteral = char_value U+0031 [concrete = constants.%.75c] -// CHECK:STDOUT: %impl.elem0.loc19: %.1e6 = impl_witness_access constants.%ImplicitAs.impl_witness.780, element0 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert] -// CHECK:STDOUT: %bound_method.loc19: = bound_method %.loc19_13.1, %impl.elem0.loc19 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.17b] -// CHECK:STDOUT: %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc19: init %char = call %bound_method.loc19(%.loc19_13.1) [concrete = constants.%int_49] -// CHECK:STDOUT: %.loc19_13.2: %char = value_of_initializer %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc19 [concrete = constants.%int_49] -// CHECK:STDOUT: %.loc19_13.3: %char = converted %.loc19_13.1, %.loc19_13.2 [concrete = constants.%int_49] -// CHECK:STDOUT: %PrintChar.call.loc19: init %i32 = call %PrintChar.ref.loc19(%.loc19_13.3) -// CHECK:STDOUT: %Core.ref: = name_ref Core, imports.%Core [concrete = imports.%Core] -// CHECK:STDOUT: %PrintChar.ref.loc20: %PrintChar.type.b3c = name_ref PrintChar, imports.%Core.PrintChar [concrete = constants.%PrintChar.063] -// CHECK:STDOUT: %.loc20_18.1: Core.CharLiteral = char_value U+0032 [concrete = constants.%.f8d] +// CHECK:STDOUT: %PrintChar.ref.loc20: %PrintChar.type.7a7 = name_ref PrintChar, file.%PrintChar.decl [concrete = constants.%PrintChar.772] +// CHECK:STDOUT: %.loc20_13.1: Core.CharLiteral = char_value U+0031 [concrete = constants.%.75c] // CHECK:STDOUT: %impl.elem0.loc20: %.1e6 = impl_witness_access constants.%ImplicitAs.impl_witness.780, element0 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert] -// CHECK:STDOUT: %bound_method.loc20: = bound_method %.loc20_18.1, %impl.elem0.loc20 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.e67] -// CHECK:STDOUT: %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc20: init %char = call %bound_method.loc20(%.loc20_18.1) [concrete = constants.%int_50] -// CHECK:STDOUT: %.loc20_18.2: %char = value_of_initializer %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc20 [concrete = constants.%int_50] -// CHECK:STDOUT: %.loc20_18.3: %char = converted %.loc20_18.1, %.loc20_18.2 [concrete = constants.%int_50] -// CHECK:STDOUT: %PrintChar.call.loc20: init %i32 = call %PrintChar.ref.loc20(%.loc20_18.3) +// CHECK:STDOUT: %bound_method.loc20: = bound_method %.loc20_13.1, %impl.elem0.loc20 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.17b] +// CHECK:STDOUT: %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc20: init %char = call %bound_method.loc20(%.loc20_13.1) [concrete = constants.%int_49] +// CHECK:STDOUT: %.loc20_13.2: %char = value_of_initializer %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc20 [concrete = constants.%int_49] +// CHECK:STDOUT: %.loc20_13.3: %char = converted %.loc20_13.1, %.loc20_13.2 [concrete = constants.%int_49] +// CHECK:STDOUT: %PrintChar.call.loc20: init %i32 = call %PrintChar.ref.loc20(%.loc20_13.3) +// CHECK:STDOUT: %Core.ref: = name_ref Core, imports.%Core [concrete = imports.%Core] +// CHECK:STDOUT: %PrintChar.ref.loc21: %PrintChar.type.b3c = name_ref PrintChar, imports.%Core.PrintChar [concrete = constants.%PrintChar.063] +// CHECK:STDOUT: %.loc21_18.1: Core.CharLiteral = char_value U+0032 [concrete = constants.%.f8d] +// CHECK:STDOUT: %impl.elem0.loc21: %.1e6 = impl_witness_access constants.%ImplicitAs.impl_witness.780, element0 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert] +// CHECK:STDOUT: %bound_method.loc21: = bound_method %.loc21_18.1, %impl.elem0.loc21 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.e67] +// CHECK:STDOUT: %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc21: init %char = call %bound_method.loc21(%.loc21_18.1) [concrete = constants.%int_50] +// CHECK:STDOUT: %.loc21_18.2: %char = value_of_initializer %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc21 [concrete = constants.%int_50] +// CHECK:STDOUT: %.loc21_18.3: %char = converted %.loc21_18.1, %.loc21_18.2 [concrete = constants.%int_50] +// CHECK:STDOUT: %PrintChar.call.loc21: init %i32 = call %PrintChar.ref.loc21(%.loc21_18.3) // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/builtins/print/int.carbon b/toolchain/check/testdata/builtins/print/int.carbon index 676b7aaead4f..733ad72be824 100644 --- a/toolchain/check/testdata/builtins/print/int.carbon +++ b/toolchain/check/testdata/builtins/print/int.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -29,7 +30,7 @@ fn Main() { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete] // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] -// CHECK:STDOUT: %Print.type.009: type = fn_type @Print.loc15 [concrete] +// CHECK:STDOUT: %Print.type.009: type = fn_type @Print.loc16 [concrete] // CHECK:STDOUT: %Print.9c5: %Print.type.009 = struct_value () [concrete] // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] // CHECK:STDOUT: %ImplicitAs.type.0ff: type = generic_interface_type @ImplicitAs [concrete] @@ -74,27 +75,27 @@ fn Main() { // CHECK:STDOUT: // CHECK:STDOUT: fn @Main() { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: %Print.ref.loc19: %Print.type.009 = name_ref Print, file.%Print.decl [concrete = constants.%Print.9c5] +// CHECK:STDOUT: %Print.ref.loc20: %Print.type.009 = name_ref Print, file.%Print.decl [concrete = constants.%Print.9c5] // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] -// CHECK:STDOUT: %impl.elem0.loc19: %.1c5 = impl_witness_access constants.%ImplicitAs.impl_witness.a23, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.e39] -// CHECK:STDOUT: %bound_method.loc19_9.1: = bound_method %int_1, %impl.elem0.loc19 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.094] -// CHECK:STDOUT: %specific_fn.loc19: = specific_function %impl.elem0.loc19, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc19_9.2: = bound_method %int_1, %specific_fn.loc19 [concrete = constants.%bound_method.953] -// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc19: init %i32 = call %bound_method.loc19_9.2(%int_1) [concrete = constants.%int_1.0c6] -// CHECK:STDOUT: %.loc19_9.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc19 [concrete = constants.%int_1.0c6] -// CHECK:STDOUT: %.loc19_9.2: %i32 = converted %int_1, %.loc19_9.1 [concrete = constants.%int_1.0c6] -// CHECK:STDOUT: %Print.call.loc19: init %empty_tuple.type = call %Print.ref.loc19(%.loc19_9.2) -// CHECK:STDOUT: %Core.ref: = name_ref Core, imports.%Core [concrete = imports.%Core] -// CHECK:STDOUT: %Print.ref.loc20: %Print.type.4a7 = name_ref Print, imports.%Core.Print [concrete = constants.%Print.d24] -// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc] // CHECK:STDOUT: %impl.elem0.loc20: %.1c5 = impl_witness_access constants.%ImplicitAs.impl_witness.a23, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.e39] -// CHECK:STDOUT: %bound_method.loc20_14.1: = bound_method %int_2, %impl.elem0.loc20 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.9f3] +// CHECK:STDOUT: %bound_method.loc20_9.1: = bound_method %int_1, %impl.elem0.loc20 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.094] // CHECK:STDOUT: %specific_fn.loc20: = specific_function %impl.elem0.loc20, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc20_14.2: = bound_method %int_2, %specific_fn.loc20 [concrete = constants.%bound_method.3cb] -// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc20: init %i32 = call %bound_method.loc20_14.2(%int_2) [concrete = constants.%int_2.295] -// CHECK:STDOUT: %.loc20_14.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc20 [concrete = constants.%int_2.295] -// CHECK:STDOUT: %.loc20_14.2: %i32 = converted %int_2, %.loc20_14.1 [concrete = constants.%int_2.295] -// CHECK:STDOUT: %Print.call.loc20: init %empty_tuple.type = call %Print.ref.loc20(%.loc20_14.2) +// CHECK:STDOUT: %bound_method.loc20_9.2: = bound_method %int_1, %specific_fn.loc20 [concrete = constants.%bound_method.953] +// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc20: init %i32 = call %bound_method.loc20_9.2(%int_1) [concrete = constants.%int_1.0c6] +// CHECK:STDOUT: %.loc20_9.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc20 [concrete = constants.%int_1.0c6] +// CHECK:STDOUT: %.loc20_9.2: %i32 = converted %int_1, %.loc20_9.1 [concrete = constants.%int_1.0c6] +// CHECK:STDOUT: %Print.call.loc20: init %empty_tuple.type = call %Print.ref.loc20(%.loc20_9.2) +// CHECK:STDOUT: %Core.ref: = name_ref Core, imports.%Core [concrete = imports.%Core] +// CHECK:STDOUT: %Print.ref.loc21: %Print.type.4a7 = name_ref Print, imports.%Core.Print [concrete = constants.%Print.d24] +// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc] +// CHECK:STDOUT: %impl.elem0.loc21: %.1c5 = impl_witness_access constants.%ImplicitAs.impl_witness.a23, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.e39] +// CHECK:STDOUT: %bound_method.loc21_14.1: = bound_method %int_2, %impl.elem0.loc21 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.9f3] +// CHECK:STDOUT: %specific_fn.loc21: = specific_function %impl.elem0.loc21, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc21_14.2: = bound_method %int_2, %specific_fn.loc21 [concrete = constants.%bound_method.3cb] +// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc21: init %i32 = call %bound_method.loc21_14.2(%int_2) [concrete = constants.%int_2.295] +// CHECK:STDOUT: %.loc21_14.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc21 [concrete = constants.%int_2.295] +// CHECK:STDOUT: %.loc21_14.2: %i32 = converted %int_2, %.loc21_14.1 [concrete = constants.%int_2.295] +// CHECK:STDOUT: %Print.call.loc21: init %empty_tuple.type = call %Print.ref.loc21(%.loc21_14.2) // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/builtins/read/char.carbon b/toolchain/check/testdata/builtins/read/char.carbon index b75d9740025c..40f293311d38 100644 --- a/toolchain/check/testdata/builtins/read/char.carbon +++ b/toolchain/check/testdata/builtins/read/char.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE diff --git a/toolchain/check/testdata/impl/interface_args.carbon b/toolchain/check/testdata/impl/interface_args.carbon index bf16b075955f..c29dc563dc60 100644 --- a/toolchain/check/testdata/impl/interface_args.carbon +++ b/toolchain/check/testdata/impl/interface_args.carbon @@ -134,10 +134,16 @@ fn InstanceC(a: A) -> C { // CHECK:STDOUT: %assoc0: %ImplicitAs.assoc_type = assoc_entity element0, @ImplicitAs.WithSelf.%ImplicitAs.WithSelf.Convert.decl [symbolic] // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core.Destroy = import_ref Core//prelude/parts/destroy, Destroy, unloaded +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Destroy = imports.%Core.Destroy // CHECK:STDOUT: .ImplicitAs = %ImplicitAs.decl // CHECK:STDOUT: } +// CHECK:STDOUT: %default.import = import // CHECK:STDOUT: %ImplicitAs.decl: %ImplicitAs.type.0ff = interface_decl @ImplicitAs [concrete = constants.%ImplicitAs.generic] { // CHECK:STDOUT: %Dest.patt.loc3_26.1: %pattern_type.98f = symbolic_binding_pattern Dest, 0 [symbolic = %Dest.patt.loc3_26.2 (constants.%Dest.patt)] // CHECK:STDOUT: } { diff --git a/toolchain/check/testdata/operators/overloaded/index.carbon b/toolchain/check/testdata/operators/overloaded/index.carbon index 955a5e6210f0..6d9f3c05e83f 100644 --- a/toolchain/check/testdata/operators/overloaded/index.carbon +++ b/toolchain/check/testdata/operators/overloaded/index.carbon @@ -84,10 +84,32 @@ fn F() { // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core.UnsafeAs = import_ref Core//prelude/parts/as, UnsafeAs, unloaded +// CHECK:STDOUT: %Core.As = import_ref Core//prelude/parts/as, As, unloaded +// CHECK:STDOUT: %Core.ImplicitAs = import_ref Core//prelude/parts/as, ImplicitAs, unloaded +// CHECK:STDOUT: %Core.BitAndWith = import_ref Core//prelude/parts/as, BitAndWith, unloaded +// CHECK:STDOUT: %Core.Copy = import_ref Core//prelude/parts/copy, Copy, unloaded +// CHECK:STDOUT: %Core.DefaultOrUnformed = import_ref Core//prelude/parts/default, DefaultOrUnformed, unloaded +// CHECK:STDOUT: %Core.Default = import_ref Core//prelude/parts/default, Default, unloaded +// CHECK:STDOUT: %Core.Destroy = import_ref Core//prelude/parts/destroy, Destroy, unloaded +// CHECK:STDOUT: %Core.Form = import_ref Core//prelude/parts/form, Form, unloaded +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .UnsafeAs = imports.%Core.UnsafeAs +// CHECK:STDOUT: .As = imports.%Core.As +// CHECK:STDOUT: .ImplicitAs = imports.%Core.ImplicitAs +// CHECK:STDOUT: .BitAndWith = imports.%Core.BitAndWith +// CHECK:STDOUT: .Copy = imports.%Core.Copy +// CHECK:STDOUT: .DefaultOrUnformed = imports.%Core.DefaultOrUnformed +// CHECK:STDOUT: .Default = imports.%Core.Default +// CHECK:STDOUT: .Destroy = imports.%Core.Destroy +// CHECK:STDOUT: .Form = imports.%Core.Form // CHECK:STDOUT: .IndexWith = %IndexWith.decl // CHECK:STDOUT: } +// CHECK:STDOUT: %default.import = import // CHECK:STDOUT: %IndexWith.decl: type = class_decl @IndexWith [concrete = constants.%IndexWith] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: @@ -210,10 +232,32 @@ fn F() { // CHECK:STDOUT: %assoc0: %IndexWith.assoc_type = assoc_entity element0, @IndexWith.WithSelf.%IndexWith.WithSelf.At.decl [symbolic] // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core.UnsafeAs = import_ref Core//prelude/parts/as, UnsafeAs, unloaded +// CHECK:STDOUT: %Core.As = import_ref Core//prelude/parts/as, As, unloaded +// CHECK:STDOUT: %Core.ImplicitAs = import_ref Core//prelude/parts/as, ImplicitAs, unloaded +// CHECK:STDOUT: %Core.BitAndWith = import_ref Core//prelude/parts/as, BitAndWith, unloaded +// CHECK:STDOUT: %Core.Copy = import_ref Core//prelude/parts/copy, Copy, unloaded +// CHECK:STDOUT: %Core.DefaultOrUnformed = import_ref Core//prelude/parts/default, DefaultOrUnformed, unloaded +// CHECK:STDOUT: %Core.Default = import_ref Core//prelude/parts/default, Default, unloaded +// CHECK:STDOUT: %Core.Destroy = import_ref Core//prelude/parts/destroy, Destroy, unloaded +// CHECK:STDOUT: %Core.Form = import_ref Core//prelude/parts/form, Form, unloaded +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .UnsafeAs = imports.%Core.UnsafeAs +// CHECK:STDOUT: .As = imports.%Core.As +// CHECK:STDOUT: .ImplicitAs = imports.%Core.ImplicitAs +// CHECK:STDOUT: .BitAndWith = imports.%Core.BitAndWith +// CHECK:STDOUT: .Copy = imports.%Core.Copy +// CHECK:STDOUT: .DefaultOrUnformed = imports.%Core.DefaultOrUnformed +// CHECK:STDOUT: .Default = imports.%Core.Default +// CHECK:STDOUT: .Destroy = imports.%Core.Destroy +// CHECK:STDOUT: .Form = imports.%Core.Form // CHECK:STDOUT: .IndexWith = %IndexWith.decl // CHECK:STDOUT: } +// CHECK:STDOUT: %default.import = import // CHECK:STDOUT: %IndexWith.decl: %IndexWith.type.df6 = interface_decl @IndexWith [concrete = constants.%IndexWith.generic] { // CHECK:STDOUT: %SubscriptType.patt.loc4_34.1: %pattern_type.98f = symbolic_binding_pattern SubscriptType, 0 [symbolic = %SubscriptType.patt.loc4_34.2 (constants.%SubscriptType.patt)] // CHECK:STDOUT: %ElementType.patt.loc4_53.1: %pattern_type.98f = symbolic_binding_pattern ElementType, 1 [symbolic = %ElementType.patt.loc4_53.2 (constants.%ElementType.patt)] diff --git a/toolchain/diagnostics/coverage_test.cpp b/toolchain/diagnostics/coverage_test.cpp index e59ddeffd71f..3409283916e2 100644 --- a/toolchain/diagnostics/coverage_test.cpp +++ b/toolchain/diagnostics/coverage_test.cpp @@ -36,10 +36,12 @@ constexpr Kind UntestedKinds[] = { Kind::BuildPreludeManifestError, Kind::BuildTempDirectoryCreationError, Kind::BuildTempDirectoryDeletionError, + Kind::CompileCoreManifestError, Kind::CompilePreludeManifestError, Kind::ConfigFailedToReadDigest, Kind::ConfigFailedToSetupTarget, Kind::DriverInstallInvalid, + Kind::LinkCarbonPreludeBuildFailed, // These diagnose filesystem issues that are hard to unit test. Kind::ErrorReadingFile, diff --git a/toolchain/diagnostics/kind.def b/toolchain/diagnostics/kind.def index 7c2e68569b13..345bc06a6ad6 100644 --- a/toolchain/diagnostics/kind.def +++ b/toolchain/diagnostics/kind.def @@ -30,6 +30,7 @@ CARBON_DIAGNOSTIC_KIND(BuildOutputFileOpenError) CARBON_DIAGNOSTIC_KIND(BuildPreludeManifestError) CARBON_DIAGNOSTIC_KIND(BuildTempDirectoryCreationError) CARBON_DIAGNOSTIC_KIND(BuildTempDirectoryDeletionError) +CARBON_DIAGNOSTIC_KIND(CompileCoreManifestError) CARBON_DIAGNOSTIC_KIND(CompilePhaseFlagConflict) CARBON_DIAGNOSTIC_KIND(CompilePreludeManifestError) CARBON_DIAGNOSTIC_KIND(CompileInputNotRegularFile) @@ -42,6 +43,7 @@ CARBON_DIAGNOSTIC_KIND(FailureBuildingRuntimes) CARBON_DIAGNOSTIC_KIND(FailureRunningClang) CARBON_DIAGNOSTIC_KIND(FailureRunningClangToLink) CARBON_DIAGNOSTIC_KIND(FormatMultipleFilesToOneOutput) +CARBON_DIAGNOSTIC_KIND(LinkCarbonPreludeBuildFailed) CARBON_DIAGNOSTIC_KIND(LinkObjectFilesMissing) CARBON_DIAGNOSTIC_KIND(LinkOutputOptionMissing) CARBON_DIAGNOSTIC_KIND(ToolFuzzingDisallowed) diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index 663e71a6fc18..911c1b4249f3 100644 --- a/toolchain/driver/BUILD +++ b/toolchain/driver/BUILD @@ -184,6 +184,8 @@ cc_library( "build_runtimes_subcommand.h", "build_subcommand.cpp", "build_subcommand.h", + "carbon_runtimes.cpp", + "carbon_runtimes.h", "clang_subcommand.cpp", "clang_subcommand.h", "compile_subcommand.cpp", @@ -235,6 +237,7 @@ cc_library( "//toolchain/base:clang_invocation", "//toolchain/base:install_paths", "//toolchain/base:llvm_tools", + "//toolchain/base:runtimes_build_info", "//toolchain/base:shared_value_stores", "//toolchain/base:timings", "//toolchain/check", diff --git a/toolchain/driver/build_runtimes_subcommand.cpp b/toolchain/driver/build_runtimes_subcommand.cpp index 88bef6e13594..a1f133ad4d1e 100644 --- a/toolchain/driver/build_runtimes_subcommand.cpp +++ b/toolchain/driver/build_runtimes_subcommand.cpp @@ -5,6 +5,7 @@ #include "toolchain/driver/build_runtimes_subcommand.h" #include "llvm/TargetParser/Triple.h" +#include "toolchain/driver/carbon_runtimes.h" #include "toolchain/driver/clang_runner.h" #include "toolchain/driver/clang_runtimes.h" @@ -97,6 +98,7 @@ auto BuildRuntimesSubcommand::RunInternal(DriverEnv& driver_env) CARBON_RETURN_IF_ERROR(runtimes.Remove(Runtimes::ClangResourceDir)); CARBON_RETURN_IF_ERROR(runtimes.Remove(Runtimes::LibUnwind)); CARBON_RETURN_IF_ERROR(runtimes.Remove(Runtimes::Libcxx)); + CARBON_RETURN_IF_ERROR(runtimes.Remove(Runtimes::CarbonCore)); } ClangResourceDirBuilder resource_dir_builder(&runner, driver_env.thread_pool, @@ -108,10 +110,13 @@ auto BuildRuntimesSubcommand::RunInternal(DriverEnv& driver_env) ClangArchiveRuntimesBuilder libcxx_builder( &runner, driver_env.thread_pool, llvm::Triple(features.target), &runtimes); + CarbonPreludeBuilder prelude_builder(&driver_env, &runtimes, + &options_.codegen_options); CARBON_RETURN_IF_ERROR(std::move(resource_dir_builder).Wait()); CARBON_RETURN_IF_ERROR(std::move(lib_unwind_builder).Wait()); CARBON_RETURN_IF_ERROR(std::move(libcxx_builder).Wait()); + CARBON_RETURN_IF_ERROR(std::move(prelude_builder).Build()); return runtimes.base_path(); } diff --git a/toolchain/driver/build_subcommand.cpp b/toolchain/driver/build_subcommand.cpp index e38a3dee1d7e..94e3cc41d9df 100644 --- a/toolchain/driver/build_subcommand.cpp +++ b/toolchain/driver/build_subcommand.cpp @@ -15,8 +15,8 @@ namespace Carbon { auto BuildSubcommandOptions::Build(CommandLine::CommandBuilder& b) -> void { - compile_options.BuildForBuildSubcommand(b); - link_options.BuildForBuildSubcommand(b); + compile_options.BuildForBuildSubcommand(b, &codegen_options); + link_options.BuildForBuildSubcommand(b, &codegen_options); b.AddFlag( { @@ -50,6 +50,8 @@ auto BuildSubcommand::BuildOptions(CommandLine::CommandBuilder& b) -> void { } auto BuildSubcommand::Run(DriverEnv& driver_env) -> DriverResult { + options_.compile_options.FixupFlags(); + if (driver_env.fuzzing && !options_.compile_options.clang_args.empty()) { // Parsing specific Clang arguments can reach deep into // external libraries that aren't fuzz clean. @@ -72,7 +74,7 @@ auto BuildSubcommand::Run(DriverEnv& driver_env) -> DriverResult { } } - auto on_exit = llvm::scope_exit([&]() { + auto on_exit = llvm::scope_exit([&] { // Clean up the temporary directory created for compile results. if (temp_dir) { auto remove_result = std::move(*temp_dir).Remove(); diff --git a/toolchain/driver/build_subcommand.h b/toolchain/driver/build_subcommand.h index 8a764e939427..51832d513398 100644 --- a/toolchain/driver/build_subcommand.h +++ b/toolchain/driver/build_subcommand.h @@ -6,6 +6,7 @@ #define CARBON_TOOLCHAIN_DRIVER_BUILD_SUBCOMMAND_H_ #include "common/command_line.h" +#include "toolchain/driver/codegen_options.h" #include "toolchain/driver/compile_options.h" #include "toolchain/driver/driver_env.h" #include "toolchain/driver/driver_subcommand.h" @@ -17,6 +18,7 @@ namespace Carbon { struct BuildSubcommandOptions { auto Build(CommandLine::CommandBuilder& b) -> void; + CodegenOptions codegen_options; CompileOptions compile_options; LinkOptions link_options; bool use_temp_dir; diff --git a/toolchain/driver/carbon_runtimes.cpp b/toolchain/driver/carbon_runtimes.cpp new file mode 100644 index 000000000000..c03613c8afbd --- /dev/null +++ b/toolchain/driver/carbon_runtimes.cpp @@ -0,0 +1,108 @@ +// 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/driver/carbon_runtimes.h" + +#include "toolchain/base/install_paths.h" +#include "toolchain/base/runtimes_build_info.h" + +namespace Carbon { + +CarbonRuntimesBuilderBase::CarbonRuntimesBuilderBase( + DriverEnv* driver_env, const CodegenOptions* codegen_options) + : compile_options_(codegen_options), + compile_driver_(&compile_options_), + driver_env_(driver_env), + install_root_(driver_env->installation->root()), + result_(Error("Did not finish building the Carbon runtimes!")) { + // Each prelude file explicitly imports the other parts of the prelude it + // needs. + compile_options_.prelude_import = false; + // Don't also try and compile the rest of the core when compiling the prelude. + compile_options_.include_carbon_core = false; +} + +CarbonPreludeBuilder::CarbonPreludeBuilder( + DriverEnv* driver_env, Runtimes* runtimes, + const CodegenOptions* codegen_options) + : CarbonRuntimesBuilderBase(driver_env, codegen_options) { + auto build_dir_or_error = runtimes->Build(Runtimes::CarbonCore); + if (!build_dir_or_error.ok()) { + result_ = std::move(build_dir_or_error).error(); + return; + } + auto build_dir = *std::move(build_dir_or_error); + if (std::holds_alternative(build_dir)) { + // Reuse cached build. + result_ = std::get(std::move(build_dir)); + return; + } + + runtimes_builder_ = std::get(std::move(build_dir)); + lib_path_ = std::filesystem::path("lib/core") / + compile_options_.codegen_options->target.str(); +} + +auto CarbonPreludeBuilder::Build() && -> ErrorOr { + // If we didn't make a Builder in the constructor we either encountered an + // error or an already cached build, return the result. + if (!runtimes_builder_) { + return std::move(result_); + } + + // Create the output directory. + auto lib_dir_result = runtimes_builder_->dir().CreateDirectories(lib_path_); + if (!lib_dir_result.ok()) { + return std::move(lib_dir_result).error(); + } + auto lib_dir = *std::move(lib_dir_result); + + // Gather the absolute paths to the prelude source files into a string list. + // This serves as a backing store for the `llvm::StringRef` inputs required to + // the `CompileDriver` via `compile_options_`. + llvm::SmallVector prelude_source_files; + llvm::for_each(RuntimesBuildInfo::CarbonCorePreludeSrcs, + [&](llvm::StringRef src) -> void { + prelude_source_files.emplace_back( + (install_root_ / std::filesystem::path(src.str()))); + compile_options_.input_filenames.emplace_back( + llvm::StringRef(prelude_source_files.back())); + }); + + auto install_root_length = install_root_.string().length(); + CARBON_CHECK( + compile_driver_.Initialize( + *driver_env_, + [&](llvm::StringRef input_filename) -> std::string { + // Make the input path relative to the install_root_ again, and + // replace the `.carbon` extension with a `.o`. + auto object_path = + std::filesystem::path( + input_filename.substr(install_root_length).str()) + .replace_extension(".o"); + auto output_path = + runtimes_builder_->path() / lib_path_ / object_path; + // The output path may contain subdirectories that haven't yet been + // created, so check for that and create if necessary. + if (!std::filesystem::exists(output_path.parent_path())) { + CARBON_CHECK( + runtimes_builder_->dir() + .CreateDirectories(lib_path_ / output_path.parent_path()) + .ok(), + "Failed to make output subdirectory while building Carbon " + "prelude."); + } + llvm::errs() << "mapping: `" << input_filename << "` to: `" + << output_path << "`\n"; + return output_path.string(); + }), + "Failed to initialize compiler driver for Carbon prelude."); + CARBON_CHECK(compile_driver_.Compile(*driver_env_).success, + "Failed to compile Carbon prelude."); + + result_ = (*std::move(runtimes_builder_)).Commit(); + return std::move(result_); +} + +} // namespace Carbon diff --git a/toolchain/driver/carbon_runtimes.h b/toolchain/driver/carbon_runtimes.h new file mode 100644 index 000000000000..e6bfbbf09c03 --- /dev/null +++ b/toolchain/driver/carbon_runtimes.h @@ -0,0 +1,65 @@ +// 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 + +#ifndef CARBON_TOOLCHAIN_DRIVER_CARBON_RUNTIMES_H_ +#define CARBON_TOOLCHAIN_DRIVER_CARBON_RUNTIMES_H_ + +#include +#include + +#include "common/error.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/ThreadPool.h" +#include "llvm/TargetParser/Triple.h" +#include "toolchain/driver/codegen_options.h" +#include "toolchain/driver/compile_driver.h" +#include "toolchain/driver/compile_options.h" +#include "toolchain/driver/driver_env.h" +#include "toolchain/driver/runtimes_cache.h" + +namespace Carbon { + +struct CompileOptions; + +// Common code for Carbon runtimes builders. +// +// Although this class has only a single derivation for building the prelude, +// we anticipate wanting to build other parts of Core in the future and so +// design for extensibility. +// TODO: Build all parts of the Core, not just the prelude. +class CarbonRuntimesBuilderBase { + protected: + CarbonRuntimesBuilderBase(DriverEnv* driver_env, + const CodegenOptions* codegen_options); + + // We use protected members as this base is just factoring out common + // implementation details of other runners. + // + // NOLINTBEGIN(misc-non-private-member-variables-in-classes) + // + CompileOptions compile_options_; + CompileDriver compile_driver_; + DriverEnv* driver_env_; + // Base path for the input source files. The enumerated constant list of + // paths is all relative to this base path. + std::filesystem::path install_root_; + // Output subpath for the built binaries. + std::filesystem::path lib_path_; + ErrorOr result_; + std::optional runtimes_builder_; + // NOLINTEND(misc-non-private-member-variables-in-classes) +}; + +class CarbonPreludeBuilder : public CarbonRuntimesBuilderBase { + public: + CarbonPreludeBuilder(DriverEnv* driver_env, Runtimes* runtimes, + const CodegenOptions* codegen_options); + auto Build() && -> ErrorOr; +}; + +} // namespace Carbon + +#endif // CARBON_TOOLCHAIN_DRIVER_CARBON_RUNTIMES_H_ diff --git a/toolchain/driver/clang_runtimes.h b/toolchain/driver/clang_runtimes.h index 37ca51db2001..8d8f53ebd9cc 100644 --- a/toolchain/driver/clang_runtimes.h +++ b/toolchain/driver/clang_runtimes.h @@ -105,8 +105,7 @@ class ClangRuntimesBuilderBase::ArchiveBuilder { // // - The `builder` must outlive this object. // - `archive_path` is the _relative_ path of the archive file within the - // built - // runtimes directory. + // built runtimes directory. // - `src_files` is a list of the _absolute_ file paths to build into the // archive. // - `cflags` are the compile flags that should be used for all the compiles diff --git a/toolchain/driver/compile_driver.cpp b/toolchain/driver/compile_driver.cpp index 929823c9af2e..26afb1be7494 100644 --- a/toolchain/driver/compile_driver.cpp +++ b/toolchain/driver/compile_driver.cpp @@ -481,9 +481,27 @@ auto CompileDriver::Initialize( } } + // Append the Core library files on request. + llvm::SmallVector core_library; + if (options_->include_carbon_core && !options_->custom_core && + options_->phase >= CompileOptions::Phase::Check) { + if (auto find = driver_env.installation->ReadCarbonCoreManifest(); + !find.ok()) { + CARBON_DIAGNOSTIC(CompileCoreManifestError, Error, "{0}", std::string); + driver_env.emitter.Emit(CompileCoreManifestError, + PrintToString(find.error())); + return false; + } else { + // Note we also compile any .impl files, as we will need to include them + // in the subsequent link step. + core_library = std::move(*find); + } + } + // Prepare CompilationUnits before building scope exit handlers. int unit_index = -1; - int total_unit_count = prelude.size() + options_->input_filenames.size(); + int total_unit_count = + prelude.size() + core_library.size() + options_->input_filenames.size(); auto unit_builder = [&](llvm::StringRef filename) { ++unit_index; return std::make_unique( @@ -491,6 +509,7 @@ auto CompileDriver::Initialize( driver_env.consumer, filename, map_input(filename), target); }; llvm::append_range(units_, llvm::map_range(prelude, unit_builder)); + llvm::append_range(units_, llvm::map_range(core_library, unit_builder)); input_filenames_index_ = units_.size(); llvm::append_range(units_, llvm::map_range(options_->input_filenames, unit_builder)); diff --git a/toolchain/driver/compile_driver.h b/toolchain/driver/compile_driver.h index f7774c2796d2..35b3ee08a868 100644 --- a/toolchain/driver/compile_driver.h +++ b/toolchain/driver/compile_driver.h @@ -238,13 +238,13 @@ class CompileDriver { // The `map_input` function maps an input file name to an output static // object name. // Returns `false` on configuration error. - auto Initialize( + [[nodiscard]] auto Initialize( DriverEnv& driver_env, llvm::function_refstd::string> map_input) -> bool; // Performs the compilation process on each input specified in the // `CompileOptions` provided at construction time. - auto Compile(DriverEnv& driver_env) -> DriverResult; + [[nodiscard]] auto Compile(DriverEnv& driver_env) -> DriverResult; // Returns the index in the `units()` array of the first input file // specified by the user on the command line. This may not be the first diff --git a/toolchain/driver/compile_options.cpp b/toolchain/driver/compile_options.cpp index 7f143854e662..9783164a326a 100644 --- a/toolchain/driver/compile_options.cpp +++ b/toolchain/driver/compile_options.cpp @@ -14,8 +14,8 @@ namespace { // Provides command-line options common to both `compile` and `link` // subcommands. -auto BuildSharedOptions(CommandLine::CommandBuilder& b, CompileOptions* options) - -> void { +auto BuildSharedOptions(CommandLine::CommandBuilder& b, CompileOptions* options, + CodegenOptions* cg_options) -> void { b.AddStringPositionalArg( { .name = "FILE", @@ -82,7 +82,8 @@ Selects the amount of optimization to perform. // Include the common code generation options at this point to render it // after the more common options above, but before the more unusual options // below. - options->codegen_options->Build(b); + cg_options->Build(b); + options->codegen_options = cg_options; b.AddFlag( { @@ -121,9 +122,10 @@ Whether to use the implicit prelude import. Enabled by default. } // namespace -auto CompileOptions::BuildForCompileSubcommand(CommandLine::CommandBuilder& b) +auto CompileOptions::BuildForCompileSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void { - BuildSharedOptions(b, this); + BuildSharedOptions(b, this, cg_options); b.AddOneOfOption( { @@ -386,11 +388,34 @@ Use the string form of the fingerprint from mangling instead of the hash form. )""", }, [&](auto& arg_b) { arg_b.Set(&mangle_string_fingerprint); }); + b.AddFlag( + { + .name = "include-carbon-core", + .help = R"""( +Automatically include the Core libraries files in the compilation. + +Note this refers to the Core libraries files other than the prelude, the +inclusion of which is currently controlled by the `prelude_import` flag. If +the `prelude_import` flag is set to false, this is also silently set to false. +)""", + }, + [&](auto& arg_b) { + arg_b.Default(true); + arg_b.Set(&include_carbon_core); + }); } -auto CompileOptions::BuildForBuildSubcommand(CommandLine::CommandBuilder& b) +auto CompileOptions::BuildForBuildSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void { - BuildSharedOptions(b, this); + include_carbon_core = true; + BuildSharedOptions(b, this, cg_options); +} + +auto CompileOptions::FixupFlags() -> void { + if (!prelude_import) { + include_carbon_core = false; + } } auto CompileOptions::ValidatePhase(Diagnostics::NoLocEmitter& emitter) const diff --git a/toolchain/driver/compile_options.h b/toolchain/driver/compile_options.h index a36a8223089d..bf78e6333d8c 100644 --- a/toolchain/driver/compile_options.h +++ b/toolchain/driver/compile_options.h @@ -5,8 +5,6 @@ #ifndef CARBON_TOOLCHAIN_DRIVER_COMPILE_OPTIONS_H_ #define CARBON_TOOLCHAIN_DRIVER_COMPILE_OPTIONS_H_ -#include - #include "common/command_line.h" #include "common/error.h" #include "common/ostream.h" @@ -31,6 +29,10 @@ namespace Carbon { // // Members are documented in their respective `Build` functions. struct CompileOptions { + CompileOptions() = default; + explicit CompileOptions(const CodegenOptions* cg_options) + : codegen_options(cg_options) {} + enum class Phase : int8_t { Lex, Parse, @@ -43,8 +45,20 @@ struct CompileOptions { friend auto operator<<(llvm::raw_ostream& out, Phase phase) -> llvm::raw_ostream&; - auto BuildForCompileSubcommand(CommandLine::CommandBuilder& b) -> void; - auto BuildForBuildSubcommand(CommandLine::CommandBuilder& b) -> void; + // Will use the provided `cg_options` to initialize the `codegen_options` + // member variable. This is provided separately so we can call `Build()` + // at a specific time in the initialization sequence for the correct priority + // of the Codegen Options build flags and help documentation. + auto BuildForCompileSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void; + auto BuildForBuildSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void; + + // It's possible to specify flags that will break the compile. In particular + // specifying `--no-prelude-import` and `--include-carbon-core` will cause + // the Core compilation to fail. This function quietly disables Carbon Core + // inclusion if the prelude import is disabled. + auto FixupFlags() -> void; // Validate that the compile options make sense for the compilation phase // selected. @@ -66,8 +80,10 @@ struct CompileOptions { -> ErrorOr>; Lower::OptimizationLevel opt_level = Lower::OptimizationLevel::Debug; - std::shared_ptr codegen_options = - std::make_shared(); + + // This pointer is set by `Build*()` functions, in other use cases this + // pointer will need to be set manually. + const CodegenOptions* codegen_options = nullptr; llvm::SmallVector input_filenames; llvm::SmallVector clang_args; @@ -97,8 +113,9 @@ struct CompileOptions { bool stream_errors = false; bool preorder_parse_tree = false; bool builtin_sem_ir = false; - bool prelude_import = false; + bool prelude_import = true; bool output_last_input_only = false; + bool include_carbon_core = true; llvm::SmallVector exclude_dump_file_prefixes; diff --git a/toolchain/driver/compile_subcommand.cpp b/toolchain/driver/compile_subcommand.cpp index 7a8fd6b96806..f2c65ebcc166 100644 --- a/toolchain/driver/compile_subcommand.cpp +++ b/toolchain/driver/compile_subcommand.cpp @@ -26,19 +26,21 @@ can be written to standard output as these phases progress. CompileSubcommand::CompileSubcommand() : DriverSubcommand(SubcommandInfo) {} auto CompileSubcommand::Run(DriverEnv& driver_env) -> DriverResult { - if (driver_env.fuzzing && !options_.clang_args.empty()) { + options_.compile_options.FixupFlags(); + + if (driver_env.fuzzing && !options_.compile_options.clang_args.empty()) { // Parsing specific Clang arguments can reach deep into // external libraries that aren't fuzz clean. TestAndDiagnoseIfFuzzingExternalLibraries(driver_env, "compile"); return {.success = false}; } - auto compile_driver = CompileDriver(&options_); + auto compile_driver = CompileDriver(&options_.compile_options); - if (!compile_driver.Initialize(driver_env, - [&](llvm::StringRef) -> std::string { - return options_.output_filename.str(); - })) { + if (!compile_driver.Initialize( + driver_env, [&](llvm::StringRef) -> std::string { + return options_.compile_options.output_filename.str(); + })) { return {.success = false}; } diff --git a/toolchain/driver/compile_subcommand.h b/toolchain/driver/compile_subcommand.h index 50f1260bbd9a..47a64ba13353 100644 --- a/toolchain/driver/compile_subcommand.h +++ b/toolchain/driver/compile_subcommand.h @@ -12,19 +12,29 @@ namespace Carbon { +// Options for the compile subcommand. +struct CompileSubcommandOptions { + auto Build(CommandLine::CommandBuilder& b) -> void { + compile_options.BuildForCompileSubcommand(b, &codegen_options); + } + + CodegenOptions codegen_options; + CompileOptions compile_options; +}; + // Implements the compile subcommand of the driver. class CompileSubcommand : public DriverSubcommand { public: explicit CompileSubcommand(); auto BuildOptions(CommandLine::CommandBuilder& b) -> void override { - options_.BuildForCompileSubcommand(b); + options_.Build(b); } auto Run(DriverEnv& driver_env) -> DriverResult override; private: - CompileOptions options_; + CompileSubcommandOptions options_; }; } // namespace Carbon diff --git a/toolchain/driver/link_driver.cpp b/toolchain/driver/link_driver.cpp index 97cb1f027020..fd4cd2d24cdd 100644 --- a/toolchain/driver/link_driver.cpp +++ b/toolchain/driver/link_driver.cpp @@ -4,10 +4,57 @@ #include "toolchain/driver/link_driver.h" +#include "common/filesystem.h" +#include "toolchain/base/runtimes_build_info.h" +#include "toolchain/driver/carbon_runtimes.h" + namespace Carbon { LinkDriver::LinkDriver(LinkOptions* options) : options_(options) {} +namespace { + +auto object_search(Filesystem::DirRef base_dir, std::filesystem::path base_path, + llvm::SmallVector& prelude_paths) -> void { + llvm::SmallVector work_paths({"."}); + while (!work_paths.empty()) { + auto relative_path = work_paths.back(); + work_paths.pop_back(); + auto relative_dir = base_dir.OpenDir(relative_path); + CARBON_CHECK(relative_dir.ok()); + llvm::SmallVector relative_sub_paths; + llvm::SmallVector relative_file_paths; + CARBON_CHECK( + relative_dir + ->AppendEntriesIf(relative_sub_paths, relative_file_paths, + [&relative_dir](llvm::StringRef name) -> bool { + auto path = std::filesystem::path(name.str()); + auto stat = relative_dir->Stat(path); + CARBON_CHECK(stat.ok()); + if (stat->is_dir()) { + return true; + } + return path.extension() == ".o"; + }) + .ok()); + llvm::append_range( + work_paths, + llvm::map_range(relative_sub_paths, + [relative_path](std::filesystem::path sub_path) { + return relative_path / sub_path; + })); + llvm::append_range( + prelude_paths, + llvm::map_range( + relative_file_paths, + [relative_path, base_path](std::filesystem::path file_path) { + return (base_path / relative_path / file_path).string(); + })); + } +} + +} // namespace + auto LinkDriver::Link(DriverEnv& driver_env) -> DriverResult { // TODO: Currently we use the Clang driver to link. This works well on Unix // OSes but we likely need to directly build logic to invoke `link.exe` on @@ -45,6 +92,51 @@ auto LinkDriver::Link(DriverEnv& driver_env) -> DriverResult { return {.success = false}; } + // Find or build the Carbon Core runtimes for linking the prelude into the + // binary. + bool include_prelude = false; + std::filesystem::path core_path; + Filesystem::DirRef runtimes_dir; + std::filesystem::path runtimes_path; + std::optional runtimes_cache; + if (options_->link_prelude_files) { + if (driver_env.prebuilt_runtimes) { + auto error_or_path = + driver_env.prebuilt_runtimes->Get(Runtimes::CarbonCore); + CARBON_CHECK(error_or_path.ok(), + "Prebuilt runtimes failed to fetch for Carbon prelude: {}", + error_or_path.error().message()); + core_path = std::move(*error_or_path); + runtimes_dir = driver_env.prebuilt_runtimes->base_dir(); + runtimes_path = driver_env.prebuilt_runtimes->base_path(); + include_prelude = true; + } else if (driver_env.build_runtimes_on_demand) { + Runtimes::Cache::Features features = { + .target = options_->codegen_options->target.str()}; + auto runtimes_or_error = driver_env.runtimes_cache.Lookup(features); + CARBON_CHECK(runtimes_or_error.ok(), "Runtimes cache lookup failed: {}", + runtimes_or_error.error().message()); + auto runtimes = std::move(*runtimes_or_error); + CarbonPreludeBuilder prelude_builder(&driver_env, &runtimes, + options_->codegen_options); + auto path_or_error = std::move(prelude_builder).Build(); + if (!path_or_error.ok()) { + CARBON_DIAGNOSTIC(LinkCarbonPreludeBuildFailed, Error, + "Failed to build Carbon prelude during linking: {0}", + std::string); + driver_env.emitter.Emit(LinkCarbonPreludeBuildFailed, + path_or_error.error().message()); + return {.success = false}; + } + core_path = std::move(*path_or_error); + runtimes_dir = runtimes.base_dir(); + runtimes_path = runtimes.base_path(); + // Keep the Runtimes object in scope so we can use it during linking. + runtimes_cache = std::move(runtimes); + include_prelude = true; + } + } + // Note that we append any extra Clang args before our object filenames. This // allows us to propagate object filenames that collide with Clang flags using // `--` before the filenames. While in theory, this could create a problem in @@ -53,6 +145,29 @@ auto LinkDriver::Link(DriverEnv& driver_env) -> DriverResult { clang_args.append(options_->extra_clang_args.begin(), options_->extra_clang_args.end()); clang_args.push_back("--"); + + // Append the Carbon prelude object files to the link. + // TODO: should also be able to link in the rest of the Core object files, + // if needed. + llvm::SmallVector prelude_paths; + if (include_prelude) { + // Open subdirectory specifically for the object files relative to the + // runtimes base path. + auto relative_path = core_path.lexically_relative(runtimes_path); + auto core_dir_or_error = runtimes_dir.OpenDir(relative_path); + CARBON_CHECK(core_dir_or_error.ok(), + "Failed to open prelude binaries directory at {}, error: {}", + runtimes_path / relative_path, core_dir_or_error.error()); + auto core_dir = std::move(*core_dir_or_error); + object_search(core_dir, core_path, prelude_paths); + CARBON_CHECK(!prelude_paths.empty(), "Found no prelude files at {}", + runtimes_path / relative_path); + llvm::append_range( + clang_args, llvm::map_range(prelude_paths, [](const std::string& path) { + return llvm::StringRef(path); + })); + } + clang_args.append(options_->object_filenames.begin(), options_->object_filenames.end()); diff --git a/toolchain/driver/link_options.cpp b/toolchain/driver/link_options.cpp index 49265b12880d..6d9af0100990 100644 --- a/toolchain/driver/link_options.cpp +++ b/toolchain/driver/link_options.cpp @@ -27,8 +27,8 @@ system mixes object files and linker flags. } // namespace -auto LinkOptions::BuildForLinkSubcommand(CommandLine::CommandBuilder& b) - -> void { +auto LinkOptions::BuildForLinkSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void { b.AddStringPositionalArg( { .name = "OBJECT_FILE", @@ -56,14 +56,27 @@ legacy parsing logic. }, [&](auto& arg_b) { arg_b.Set(&output_filename); }); - BuildSharedOptions(b, this); + b.AddFlag( + { + .name = "link_prelude_files", + .help = R"""( +Automatically include the Carbon prelude files in the link. +)""", + }, + [&](auto& arg_b) { + arg_b.Default(true); + arg_b.Set(&link_prelude_files); + }); - codegen_options = std::make_shared(); - codegen_options->Build(b); + BuildSharedOptions(b, this); + cg_options->Build(b); + codegen_options = cg_options; } -auto LinkOptions::BuildForBuildSubcommand(CommandLine::CommandBuilder& b) - -> void { +auto LinkOptions::BuildForBuildSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void { + codegen_options = cg_options; + b.AddStringOption( { .name = "output", @@ -77,6 +90,9 @@ name of the first provided input file. [&](auto& arg_b) { arg_b.Set(&output_filename); }); BuildSharedOptions(b, this); + // The prelude files have already been built and are part of the input binary + // set, so will already be linked through that path. + link_prelude_files = false; } } // namespace Carbon diff --git a/toolchain/driver/link_options.h b/toolchain/driver/link_options.h index 0c442fce618e..564bc9e79b80 100644 --- a/toolchain/driver/link_options.h +++ b/toolchain/driver/link_options.h @@ -5,8 +5,6 @@ #ifndef CARBON_TOOLCHAIN_DRIVER_LINK_OPTIONS_H_ #define CARBON_TOOLCHAIN_DRIVER_LINK_OPTIONS_H_ -#include - #include "common/command_line.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -20,11 +18,14 @@ namespace Carbon { // // See the implementation of `link` for documentation on members. struct LinkOptions { - auto BuildForLinkSubcommand(CommandLine::CommandBuilder& b) -> void; - auto BuildForBuildSubcommand(CommandLine::CommandBuilder& b) -> void; + auto BuildForLinkSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void; + auto BuildForBuildSubcommand(CommandLine::CommandBuilder& b, + CodegenOptions* cg_options) -> void; - std::shared_ptr codegen_options; + const CodegenOptions* codegen_options = nullptr; llvm::StringRef output_filename; + bool link_prelude_files = true; llvm::SmallVector object_filenames; llvm::SmallVector extra_clang_args; diff --git a/toolchain/driver/link_subcommand.h b/toolchain/driver/link_subcommand.h index f074998a8e69..d338bc2dae4c 100644 --- a/toolchain/driver/link_subcommand.h +++ b/toolchain/driver/link_subcommand.h @@ -21,12 +21,13 @@ class LinkSubcommand : public DriverSubcommand { explicit LinkSubcommand(); auto BuildOptions(CommandLine::CommandBuilder& b) -> void override { - options_.BuildForLinkSubcommand(b); + options_.BuildForLinkSubcommand(b, &codegen_options); } auto Run(DriverEnv& driver_env) -> DriverResult override; private: + CodegenOptions codegen_options; LinkOptions options_; }; diff --git a/toolchain/driver/runtimes_cache.h b/toolchain/driver/runtimes_cache.h index e33bccc65630..b2710b9ab81e 100644 --- a/toolchain/driver/runtimes_cache.h +++ b/toolchain/driver/runtimes_cache.h @@ -36,15 +36,13 @@ namespace Carbon { // build of these components into their designated subdirectories, including // synchronizing between different threads or processes trying to build the same // component. -// -// TODO: Add libc++ to the runtimes tree. -// TODO: Add the Core library to the runtimes tree. class Runtimes { public: class Builder; class Cache; enum Component { + CarbonCore, ClangResourceDir, LibUnwind, Libcxx, @@ -153,6 +151,8 @@ class Runtimes { // This uses `std::string_view` to simply using with paths. static constexpr auto ComponentPath(Component component) -> std::string_view { switch (component) { + case CarbonCore: + return "core"; case ClangResourceDir: return "clang_resource_dir"; case LibUnwind: diff --git a/toolchain/driver/testdata/compile/optimize/optimize_debug.carbon b/toolchain/driver/testdata/compile/optimize/optimize_debug.carbon index 5f0209a25597..32a9b2ce0712 100644 --- a/toolchain/driver/testdata/compile/optimize/optimize_debug.carbon +++ b/toolchain/driver/testdata/compile/optimize/optimize_debug.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: compile --optimize=debug foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} +// ARGS: compile --optimize=debug foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} --include-carbon-core // // AUTOUPDATE // TIP: To test this file alone, run: diff --git a/toolchain/driver/testdata/compile/optimize/optimize_default.carbon b/toolchain/driver/testdata/compile/optimize/optimize_default.carbon index 7af27c466e10..70288c9d8971 100644 --- a/toolchain/driver/testdata/compile/optimize/optimize_default.carbon +++ b/toolchain/driver/testdata/compile/optimize/optimize_default.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: compile foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} +// ARGS: compile foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} --include-carbon-core // // AUTOUPDATE // TIP: To test this file alone, run: diff --git a/toolchain/driver/testdata/compile/optimize/optimize_none.carbon b/toolchain/driver/testdata/compile/optimize/optimize_none.carbon index 1e7f8d1a5020..0e8b5ecbdb58 100644 --- a/toolchain/driver/testdata/compile/optimize/optimize_none.carbon +++ b/toolchain/driver/testdata/compile/optimize/optimize_none.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: compile --optimize=none foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} +// ARGS: compile --optimize=none foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} --include-carbon-core // // AUTOUPDATE // TIP: To test this file alone, run: diff --git a/toolchain/driver/testdata/compile/optimize/optimize_size.carbon b/toolchain/driver/testdata/compile/optimize/optimize_size.carbon index ccbcb772ee5c..3d7be7a29135 100644 --- a/toolchain/driver/testdata/compile/optimize/optimize_size.carbon +++ b/toolchain/driver/testdata/compile/optimize/optimize_size.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: compile --optimize=size foo.carbon --target=x86_64-unknown-linux-gnu --phase=lower --dump-llvm-ir --exclude-dump-file-prefix=%{core} +// ARGS: compile --optimize=size foo.carbon --target=x86_64-unknown-linux-gnu --phase=lower --dump-llvm-ir --exclude-dump-file-prefix=%{core} --include-carbon-core // // AUTOUPDATE // TIP: To test this file alone, run: diff --git a/toolchain/driver/testdata/compile/optimize/optimize_speed.carbon b/toolchain/driver/testdata/compile/optimize/optimize_speed.carbon index 201fbdcec6bd..b0661757b907 100644 --- a/toolchain/driver/testdata/compile/optimize/optimize_speed.carbon +++ b/toolchain/driver/testdata/compile/optimize/optimize_speed.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: compile --optimize=speed foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} +// ARGS: compile --optimize=speed foo.carbon --target=x86_64-unknown-linux-gnu --phase=optimize --dump-llvm-ir --exclude-dump-file-prefix=%{core} --include-carbon-core // // AUTOUPDATE // TIP: To test this file alone, run: diff --git a/toolchain/driver/testdata/verbose.carbon b/toolchain/driver/testdata/verbose.carbon index fec645e48e4e..99600a95a4b9 100644 --- a/toolchain/driver/testdata/verbose.carbon +++ b/toolchain/driver/testdata/verbose.carbon @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon -// ARGS: -v compile --phase=codegen --target=x86_64-unknown-linux-gnu --output=%t --output-last-input-only %s +// ARGS: -v compile --phase=codegen --target=x86_64-unknown-linux-gnu --output=%t --no-include-carbon-core --output-last-input-only %s // // Verifies that various phases are included in vlog output. // diff --git a/toolchain/install/BUILD b/toolchain/install/BUILD index 0994fa8e85ce..0fe693273d6a 100644 --- a/toolchain/install/BUILD +++ b/toolchain/install/BUILD @@ -34,6 +34,7 @@ load( load("@llvm-project//libcxx:libcxx_library.bzl", "libcxx_and_abi_copts") load("@llvm-project//libunwind:libunwind_library.bzl", "libunwind_copts") load("@rules_python//python:defs.bzl", "py_test") +load("//bazel/carbon_rules:defs.bzl", "carbon_prelude") load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test") load( "//bazel/cc_toolchains:carbon_bootstrapping.bzl", @@ -147,6 +148,12 @@ toolchain_files( prefix = "core/", ) +toolchain_files( + name = "core_library", + srcs = ["//core:core_library"], + prefix = "core/", +) + toolchain_files( name = "clang_builtin_hdrs", srcs = ["@llvm-project//clang:builtin_headers_gen"], @@ -367,6 +374,7 @@ filegroup( ":builtins_all_srcs", ":clang_hdrs", ":core", + ":core_library", ":install_marker", ":installed_bazel_files", ":libc_internal_libcxx_hdrs", @@ -483,6 +491,15 @@ filegroup( output_group = "archive", ) +carbon_prelude( + name = "carbon_prelude", + srcs = [":core"], + target_compatible_with = select({ + ":is_runtimes_build": [], + "//conditions:default": ["@platforms//:incompatible"], + }), +) + cc_library( name = "libunwind", srcs = [":libunwind_srcs"], @@ -576,6 +593,7 @@ filegroup( carbon_runtimes_config( name = "runtimes_cfg", builtins_archive = ":builtins_archive", + carbon_prelude_prebuilt = ":carbon_prelude", clang_hdrs_prefix = "llvm/lib/clang/{0}/include/".format(LLVM_VERSION_MAJOR), crt_copts = crt_copts + [ # Disable all sanitizers for CRT objects. diff --git a/toolchain/install/install_test.py b/toolchain/install/install_test.py index 38ef265b374d..24aa65510084 100644 --- a/toolchain/install/install_test.py +++ b/toolchain/install/install_test.py @@ -135,7 +135,13 @@ class InstallTest(unittest.TestCase): try: obj_file = self.tmpdir / f"{name}.o" subprocess.run( - [carbon, "compile", f"--output={obj_file}", src_file], + [ + carbon, + "compile", + "--no-include-carbon-core", + f"--output={obj_file}", + src_file, + ], check=True, capture_output=True, text=True, diff --git a/toolchain/language_server/BUILD b/toolchain/language_server/BUILD index 6c675a1a47a6..c1ad6f92d726 100644 --- a/toolchain/language_server/BUILD +++ b/toolchain/language_server/BUILD @@ -41,6 +41,7 @@ cc_library( "//toolchain/check", "//toolchain/diagnostics:emitter", "//toolchain/diagnostics:file_diagnostics", + "//toolchain/driver:codegen_options", "//toolchain/driver:compile_driver", "//toolchain/lex", "//toolchain/lex:tokenized_buffer", diff --git a/toolchain/language_server/context.cpp b/toolchain/language_server/context.cpp index df58a4ba49ba..28d26f85800b 100644 --- a/toolchain/language_server/context.cpp +++ b/toolchain/language_server/context.cpp @@ -228,11 +228,13 @@ auto Context::File::SetText(Context& context, std::optional version, driver_env.vlog_stream = static_cast(context.vlog_stream()); - options_ = CompileOptions(); - options_.codegen_options->target = options_.codegen_options->host; + codegen_options_ = CodegenOptions(); + options_ = CompileOptions(&codegen_options_); + codegen_options_.target = codegen_options_.host; options_.phase = CompileOptions::Phase::Check; options_.prelude_import = context.prelude_import(); options_.input_filenames.push_back(filename()); + options_.FixupFlags(); compile_driver_ = std::make_unique(&options_); auto map_input = [](llvm::StringRef) -> std::string { return ""; }; @@ -240,7 +242,10 @@ auto Context::File::SetText(Context& context, std::optional version, context.PublishDiagnostics(consumer.params()); return; } - compile_driver_->Compile(driver_env); + if (!compile_driver_->Compile(driver_env).success) { + context.PublishDiagnostics(consumer.params()); + return; + } // Note we need to publish diagnostics even when empty. // TODO: Consider caching previously published diagnostics and only publishing diff --git a/toolchain/language_server/context.h b/toolchain/language_server/context.h index 1f4b813a64bc..ed80d18ecd5a 100644 --- a/toolchain/language_server/context.h +++ b/toolchain/language_server/context.h @@ -15,7 +15,9 @@ #include "toolchain/diagnostics/consumer.h" #include "toolchain/diagnostics/emitter.h" #include "toolchain/diagnostics/file_diagnostics.h" +#include "toolchain/driver/codegen_options.h" #include "toolchain/driver/compile_driver.h" +#include "toolchain/driver/compile_options.h" #include "toolchain/lex/tokenized_buffer.h" #include "toolchain/parse/tree_and_subtrees.h" #include "toolchain/sem_ir/file.h" @@ -29,7 +31,9 @@ class Context { class File { public: explicit File(clang::clangd::URIForFile uri) - : uri_(std::move(uri)), filename_(uri_.file().str()) {} + : uri_(std::move(uri)), + filename_(uri_.file().str()), + options_(&codegen_options_) {} // Changes the file's text, updating dependent state. auto SetText(Context& context, std::optional version, @@ -51,6 +55,8 @@ class Context { // Current file content, and derived values. std::string text_; + + CodegenOptions codegen_options_; CompileOptions options_; std::unique_ptr compile_driver_; }; diff --git a/toolchain/lower/testdata/builtins/print_read.carbon b/toolchain/lower/testdata/builtins/print_read.carbon index 7dfbd5771677..ebccf4912b20 100644 --- a/toolchain/lower/testdata/builtins/print_read.carbon +++ b/toolchain/lower/testdata/builtins/print_read.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -41,16 +42,16 @@ fn Main() { // CHECK:STDOUT: // CHECK:STDOUT: while.cond: ; preds = %if.else, %entry // CHECK:STDOUT: %ReadChar.call = call i32 @getchar(), !dbg !9 -// CHECK:STDOUT: %Int.as.EqWith.impl.NotEqual.call.loc22 = icmp ne i32 %ReadChar.call, -1, !dbg !9 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.NotEqual.call.loc22, label %while.body, label %while.done, !dbg !8 +// CHECK:STDOUT: %Int.as.EqWith.impl.NotEqual.call.loc23 = icmp ne i32 %ReadChar.call, -1, !dbg !9 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.NotEqual.call.loc23, label %while.body, label %while.done, !dbg !8 // CHECK:STDOUT: // CHECK:STDOUT: while.body: ; preds = %while.cond -// CHECK:STDOUT: %PrintChar.call.loc24 = call i32 @putchar(i32 72), !dbg !10 -// CHECK:STDOUT: %Int.as.EqWith.impl.NotEqual.call.loc24 = icmp ne i32 %PrintChar.call.loc24, -1, !dbg !10 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.NotEqual.call.loc24, label %if.then, label %if.else, !dbg !11 +// CHECK:STDOUT: %PrintChar.call.loc25 = call i32 @putchar(i32 72), !dbg !10 +// CHECK:STDOUT: %Int.as.EqWith.impl.NotEqual.call.loc25 = icmp ne i32 %PrintChar.call.loc25, -1, !dbg !10 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.NotEqual.call.loc25, label %if.then, label %if.else, !dbg !11 // CHECK:STDOUT: // CHECK:STDOUT: if.then: ; preds = %while.body -// CHECK:STDOUT: %PrintChar.call.loc25 = call i32 @putchar(i32 105), !dbg !12 +// CHECK:STDOUT: %PrintChar.call.loc26 = call i32 @putchar(i32 105), !dbg !12 // CHECK:STDOUT: br label %if.else, !dbg !13 // CHECK:STDOUT: // CHECK:STDOUT: if.else: ; preds = %if.then, %while.body @@ -78,16 +79,16 @@ fn Main() { // CHECK:STDOUT: !1 = !DIFile(filename: "print_read.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Main", linkageName: "_CMain.Main", scope: null, file: !1, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Main", linkageName: "_CMain.Main", scope: null, file: !1, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{null} -// CHECK:STDOUT: !7 = !DILocation(line: 19, column: 3, scope: !4) -// CHECK:STDOUT: !8 = !DILocation(line: 22, column: 9, scope: !4) -// CHECK:STDOUT: !9 = !DILocation(line: 22, column: 10, scope: !4) -// CHECK:STDOUT: !10 = !DILocation(line: 24, column: 9, scope: !4) -// CHECK:STDOUT: !11 = !DILocation(line: 24, column: 8, scope: !4) -// CHECK:STDOUT: !12 = !DILocation(line: 25, column: 7, scope: !4) -// CHECK:STDOUT: !13 = !DILocation(line: 24, column: 5, scope: !4) -// CHECK:STDOUT: !14 = !DILocation(line: 22, column: 3, scope: !4) -// CHECK:STDOUT: !15 = !DILocation(line: 18, column: 1, scope: !4) +// CHECK:STDOUT: !7 = !DILocation(line: 20, column: 3, scope: !4) +// CHECK:STDOUT: !8 = !DILocation(line: 23, column: 9, scope: !4) +// CHECK:STDOUT: !9 = !DILocation(line: 23, column: 10, scope: !4) +// CHECK:STDOUT: !10 = !DILocation(line: 25, column: 9, scope: !4) +// CHECK:STDOUT: !11 = !DILocation(line: 25, column: 8, scope: !4) +// CHECK:STDOUT: !12 = !DILocation(line: 26, column: 7, scope: !4) +// CHECK:STDOUT: !13 = !DILocation(line: 25, column: 5, scope: !4) +// CHECK:STDOUT: !14 = !DILocation(line: 23, column: 3, scope: !4) +// CHECK:STDOUT: !15 = !DILocation(line: 19, column: 1, scope: !4) // CHECK:STDOUT: diff --git a/toolchain/lower/testdata/for/break_continue.carbon b/toolchain/lower/testdata/for/break_continue.carbon index 0a622893b574..c548803b8eb8 100644 --- a/toolchain/lower/testdata/for/break_continue.carbon +++ b/toolchain/lower/testdata/for/break_continue.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -37,47 +38,47 @@ fn For() { // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define void @_CFor.Main() #0 !dbg !4 { // CHECK:STDOUT: entry: -// CHECK:STDOUT: %.loc20_32.1.temp = alloca { i32, i32 }, align 4, !dbg !7 +// CHECK:STDOUT: %.loc21_32.1.temp = alloca { i32, i32 }, align 4, !dbg !7 // CHECK:STDOUT: %var = alloca i32, align 4, !dbg !8 -// CHECK:STDOUT: %.loc20_33.1.temp = alloca <{ i32, i1 }>, align 4, !dbg !8 -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc20_32.1.temp), !dbg !7 -// CHECK:STDOUT: call void @_CRange.Core(ptr %.loc20_32.1.temp, i32 100), !dbg !7 -// CHECK:STDOUT: %IntRange.as.Iterate.impl.NewCursor.call = call i32 @"_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc20_32.1.temp), !dbg !8 +// CHECK:STDOUT: %.loc21_33.1.temp = alloca <{ i32, i1 }>, align 4, !dbg !8 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc21_32.1.temp), !dbg !7 +// CHECK:STDOUT: call void @_CRange.Core(ptr %.loc21_32.1.temp, i32 100), !dbg !7 +// CHECK:STDOUT: %IntRange.as.Iterate.impl.NewCursor.call = call i32 @"_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc21_32.1.temp), !dbg !8 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %var), !dbg !8 // CHECK:STDOUT: store i32 %IntRange.as.Iterate.impl.NewCursor.call, ptr %var, align 4, !dbg !8 // CHECK:STDOUT: br label %for.next, !dbg !8 // CHECK:STDOUT: -// CHECK:STDOUT: for.next: ; preds = %if.else.loc22, %if.then.loc22, %entry -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc20_33.1.temp), !dbg !8 -// CHECK:STDOUT: call void @"_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc20_33.1.temp, ptr %.loc20_32.1.temp, ptr %var), !dbg !8 -// CHECK:STDOUT: %Optional.HasValue.call = call i1 @_CHasValue.Optional.Core.329ac87584bc77f7(ptr %.loc20_33.1.temp), !dbg !8 +// CHECK:STDOUT: for.next: ; preds = %if.else.loc23, %if.then.loc23, %entry +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc21_33.1.temp), !dbg !8 +// CHECK:STDOUT: call void @"_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc21_33.1.temp, ptr %.loc21_32.1.temp, ptr %var), !dbg !8 +// CHECK:STDOUT: %Optional.HasValue.call = call i1 @_CHasValue.Optional.Core.329ac87584bc77f7(ptr %.loc21_33.1.temp), !dbg !8 // CHECK:STDOUT: br i1 %Optional.HasValue.call, label %for.body, label %for.done, !dbg !8 // CHECK:STDOUT: // CHECK:STDOUT: for.body: ; preds = %for.next -// CHECK:STDOUT: %Optional.Get.call = call i32 @_CGet.Optional.Core.329ac87584bc77f7(ptr %.loc20_33.1.temp), !dbg !8 +// CHECK:STDOUT: %Optional.Get.call = call i32 @_CGet.Optional.Core.329ac87584bc77f7(ptr %.loc21_33.1.temp), !dbg !8 // CHECK:STDOUT: %F.call = call i1 @_CF.Main(), !dbg !9 -// CHECK:STDOUT: br i1 %F.call, label %if.then.loc21, label %if.else.loc21, !dbg !10 +// CHECK:STDOUT: br i1 %F.call, label %if.then.loc22, label %if.else.loc22, !dbg !10 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc21: ; preds = %for.body +// CHECK:STDOUT: if.then.loc22: ; preds = %for.body // CHECK:STDOUT: br label %for.done, !dbg !11 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc21: ; preds = %for.body +// CHECK:STDOUT: if.else.loc22: ; preds = %for.body // CHECK:STDOUT: %G.call = call i1 @_CG.Main(), !dbg !12 -// CHECK:STDOUT: br i1 %G.call, label %if.then.loc22, label %if.else.loc22, !dbg !13 +// CHECK:STDOUT: br i1 %G.call, label %if.then.loc23, label %if.else.loc23, !dbg !13 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc22: ; preds = %if.else.loc21 -// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc20_33.1.temp), !dbg !8 +// CHECK:STDOUT: if.then.loc23: ; preds = %if.else.loc22 +// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc21_33.1.temp), !dbg !8 // CHECK:STDOUT: br label %for.next, !dbg !14 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc22: ; preds = %if.else.loc21 +// CHECK:STDOUT: if.else.loc23: ; preds = %if.else.loc22 // CHECK:STDOUT: call void @_CH.Main(), !dbg !15 -// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc20_33.1.temp), !dbg !8 +// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc21_33.1.temp), !dbg !8 // CHECK:STDOUT: br label %for.next, !dbg !16 // CHECK:STDOUT: -// CHECK:STDOUT: for.done: ; preds = %if.then.loc21, %for.next -// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc20_33.1.temp), !dbg !8 +// CHECK:STDOUT: for.done: ; preds = %if.then.loc22, %for.next +// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc21_33.1.temp), !dbg !8 // CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %var), !dbg !8 -// CHECK:STDOUT: call void @"_COp.0d5da2659ce22e5f:core.Destroy.Core"(ptr %.loc20_32.1.temp), !dbg !7 +// CHECK:STDOUT: call void @"_COp.0d5da2659ce22e5f:core.Destroy.Core"(ptr %.loc21_32.1.temp), !dbg !7 // CHECK:STDOUT: ret void, !dbg !17 // CHECK:STDOUT: } // CHECK:STDOUT: @@ -268,83 +269,83 @@ fn For() { // CHECK:STDOUT: !1 = !DIFile(filename: "break_continue.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "For", linkageName: "_CFor.Main", scope: null, file: !1, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "For", linkageName: "_CFor.Main", scope: null, file: !1, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{null} -// CHECK:STDOUT: !7 = !DILocation(line: 20, column: 18, scope: !4) -// CHECK:STDOUT: !8 = !DILocation(line: 20, column: 7, scope: !4) -// CHECK:STDOUT: !9 = !DILocation(line: 21, column: 9, scope: !4) -// CHECK:STDOUT: !10 = !DILocation(line: 21, column: 8, scope: !4) -// CHECK:STDOUT: !11 = !DILocation(line: 21, column: 16, scope: !4) -// CHECK:STDOUT: !12 = !DILocation(line: 22, column: 9, scope: !4) -// CHECK:STDOUT: !13 = !DILocation(line: 22, column: 8, scope: !4) -// CHECK:STDOUT: !14 = !DILocation(line: 22, column: 16, scope: !4) -// CHECK:STDOUT: !15 = !DILocation(line: 23, column: 5, scope: !4) -// CHECK:STDOUT: !16 = !DILocation(line: 20, column: 3, scope: !4) -// CHECK:STDOUT: !17 = !DILocation(line: 19, column: 1, scope: !4) -// CHECK:STDOUT: !18 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !19, line: 24, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !23) +// CHECK:STDOUT: !7 = !DILocation(line: 21, column: 18, scope: !4) +// CHECK:STDOUT: !8 = !DILocation(line: 21, column: 7, scope: !4) +// CHECK:STDOUT: !9 = !DILocation(line: 22, column: 9, scope: !4) +// CHECK:STDOUT: !10 = !DILocation(line: 22, column: 8, scope: !4) +// CHECK:STDOUT: !11 = !DILocation(line: 22, column: 16, scope: !4) +// CHECK:STDOUT: !12 = !DILocation(line: 23, column: 9, scope: !4) +// CHECK:STDOUT: !13 = !DILocation(line: 23, column: 8, scope: !4) +// CHECK:STDOUT: !14 = !DILocation(line: 23, column: 16, scope: !4) +// CHECK:STDOUT: !15 = !DILocation(line: 24, column: 5, scope: !4) +// CHECK:STDOUT: !16 = !DILocation(line: 21, column: 3, scope: !4) +// CHECK:STDOUT: !17 = !DILocation(line: 20, column: 1, scope: !4) +// CHECK:STDOUT: !18 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !19, line: 15, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !23) // CHECK:STDOUT: !19 = !DIFile(filename: "{{.*}}/range.carbon", directory: "") // CHECK:STDOUT: !20 = !DISubroutineType(types: !21) // CHECK:STDOUT: !21 = !{null, !22} // CHECK:STDOUT: !22 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) // CHECK:STDOUT: !23 = !{!24} // CHECK:STDOUT: !24 = !DILocalVariable(arg: 1, scope: !18, type: !22) -// CHECK:STDOUT: !25 = !DILocation(line: 24, column: 39, scope: !18) -// CHECK:STDOUT: !26 = distinct !DISubprogram(name: "Op", linkageName: "_COp.94ba1c30d421702e:core.Destroy.Core", scope: null, file: !1, line: 20, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !30) +// CHECK:STDOUT: !25 = !DILocation(line: 15, column: 39, scope: !18) +// CHECK:STDOUT: !26 = distinct !DISubprogram(name: "Op", linkageName: "_COp.94ba1c30d421702e:core.Destroy.Core", scope: null, file: !1, line: 21, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !30) // CHECK:STDOUT: !27 = !DISubroutineType(types: !28) // CHECK:STDOUT: !28 = !{null, !29} // CHECK:STDOUT: !29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) // CHECK:STDOUT: !30 = !{!31} // CHECK:STDOUT: !31 = !DILocalVariable(arg: 1, scope: !26, type: !29) -// CHECK:STDOUT: !32 = !DILocation(line: 20, column: 7, scope: !26) -// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0fc9634857315db2:core.Destroy.Core", scope: null, file: !1, line: 20, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !34) +// CHECK:STDOUT: !32 = !DILocation(line: 21, column: 7, scope: !26) +// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0fc9634857315db2:core.Destroy.Core", scope: null, file: !1, line: 21, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !34) // CHECK:STDOUT: !34 = !{!35} // CHECK:STDOUT: !35 = !DILocalVariable(arg: 1, scope: !33, type: !22) -// CHECK:STDOUT: !36 = !DILocation(line: 20, column: 7, scope: !33) -// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "Op", linkageName: "_COp.69700c1fc1b2744c:core.Destroy.Core", scope: null, file: !1, line: 20, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !38) +// CHECK:STDOUT: !36 = !DILocation(line: 21, column: 7, scope: !33) +// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "Op", linkageName: "_COp.69700c1fc1b2744c:core.Destroy.Core", scope: null, file: !1, line: 21, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !38) // CHECK:STDOUT: !38 = !{!39} // CHECK:STDOUT: !39 = !DILocalVariable(arg: 1, scope: !37, type: !29) -// CHECK:STDOUT: !40 = !DILocation(line: 20, column: 7, scope: !37) -// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "Op", linkageName: "_COp.278d9a31079e7ff2:core.Destroy.Core", scope: null, file: !1, line: 20, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !42) +// CHECK:STDOUT: !40 = !DILocation(line: 21, column: 7, scope: !37) +// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "Op", linkageName: "_COp.278d9a31079e7ff2:core.Destroy.Core", scope: null, file: !1, line: 21, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !42) // CHECK:STDOUT: !42 = !{!43} // CHECK:STDOUT: !43 = !DILocalVariable(arg: 1, scope: !41, type: !29) -// CHECK:STDOUT: !44 = !DILocation(line: 20, column: 7, scope: !41) -// CHECK:STDOUT: !45 = distinct !DISubprogram(name: "Op", linkageName: "_COp.f9d363db90f1ff8b:core.Destroy.Core", scope: null, file: !1, line: 20, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !46) +// CHECK:STDOUT: !44 = !DILocation(line: 21, column: 7, scope: !41) +// CHECK:STDOUT: !45 = distinct !DISubprogram(name: "Op", linkageName: "_COp.f9d363db90f1ff8b:core.Destroy.Core", scope: null, file: !1, line: 21, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !46) // CHECK:STDOUT: !46 = !{!47} // CHECK:STDOUT: !47 = !DILocalVariable(arg: 1, scope: !45, type: !29) -// CHECK:STDOUT: !48 = !DILocation(line: 20, column: 7, scope: !45) -// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Op", linkageName: "_COp.db43fa38232c28dd:core.Destroy.Core", scope: null, file: !1, line: 20, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !50) +// CHECK:STDOUT: !48 = !DILocation(line: 21, column: 7, scope: !45) +// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Op", linkageName: "_COp.db43fa38232c28dd:core.Destroy.Core", scope: null, file: !1, line: 21, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !50) // CHECK:STDOUT: !50 = !{!51} // CHECK:STDOUT: !51 = !DILocalVariable(arg: 1, scope: !49, type: !29) -// CHECK:STDOUT: !52 = !DILocation(line: 20, column: 18, scope: !49) -// CHECK:STDOUT: !53 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0d5da2659ce22e5f:core.Destroy.Core", scope: null, file: !1, line: 20, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !54) +// CHECK:STDOUT: !52 = !DILocation(line: 21, column: 18, scope: !49) +// CHECK:STDOUT: !53 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0d5da2659ce22e5f:core.Destroy.Core", scope: null, file: !1, line: 21, type: !27, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !54) // CHECK:STDOUT: !54 = !{!55} // CHECK:STDOUT: !55 = !DILocalVariable(arg: 1, scope: !53, type: !29) -// CHECK:STDOUT: !56 = !DILocation(line: 20, column: 18, scope: !53) -// CHECK:STDOUT: !57 = distinct !DISubprogram(name: "NewCursor", linkageName: "_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !19, line: 25, type: !58, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !60) +// CHECK:STDOUT: !56 = !DILocation(line: 21, column: 18, scope: !53) +// CHECK:STDOUT: !57 = distinct !DISubprogram(name: "NewCursor", linkageName: "_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !19, line: 16, type: !58, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !60) // CHECK:STDOUT: !58 = !DISubroutineType(types: !59) // CHECK:STDOUT: !59 = !{!22, !29} // CHECK:STDOUT: !60 = !{!61} // CHECK:STDOUT: !61 = !DILocalVariable(arg: 1, scope: !57, type: !29) -// CHECK:STDOUT: !62 = !DILocation(line: 25, column: 43, scope: !57) -// CHECK:STDOUT: !63 = !DILocation(line: 25, column: 36, scope: !57) -// CHECK:STDOUT: !64 = distinct !DISubprogram(name: "Next", linkageName: "_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !19, line: 26, type: !65, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !67) +// CHECK:STDOUT: !62 = !DILocation(line: 16, column: 43, scope: !57) +// CHECK:STDOUT: !63 = !DILocation(line: 16, column: 36, scope: !57) +// CHECK:STDOUT: !64 = distinct !DISubprogram(name: "Next", linkageName: "_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !19, line: 17, type: !65, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !67) // CHECK:STDOUT: !65 = !DISubroutineType(types: !66) // CHECK:STDOUT: !66 = !{!29, !29, !29} // CHECK:STDOUT: !67 = !{!68, !69} // CHECK:STDOUT: !68 = !DILocalVariable(arg: 1, scope: !64, type: !29) // CHECK:STDOUT: !69 = !DILocalVariable(arg: 2, scope: !64, type: !29) -// CHECK:STDOUT: !70 = !DILocation(line: 27, column: 7, scope: !64) -// CHECK:STDOUT: !71 = !DILocation(line: 27, column: 27, scope: !64) -// CHECK:STDOUT: !72 = !DILocation(line: 28, column: 19, scope: !64) -// CHECK:STDOUT: !73 = !DILocation(line: 28, column: 11, scope: !64) -// CHECK:STDOUT: !74 = !DILocation(line: 28, column: 10, scope: !64) -// CHECK:STDOUT: !75 = !DILocation(line: 29, column: 9, scope: !64) -// CHECK:STDOUT: !76 = !DILocation(line: 30, column: 38, scope: !64) -// CHECK:STDOUT: !77 = !DILocation(line: 30, column: 16, scope: !64) -// CHECK:STDOUT: !78 = !DILocation(line: 30, column: 9, scope: !64) -// CHECK:STDOUT: !79 = !DILocation(line: 32, column: 16, scope: !64) -// CHECK:STDOUT: !80 = !DILocation(line: 32, column: 9, scope: !64) +// CHECK:STDOUT: !70 = !DILocation(line: 18, column: 7, scope: !64) +// CHECK:STDOUT: !71 = !DILocation(line: 18, column: 27, scope: !64) +// CHECK:STDOUT: !72 = !DILocation(line: 19, column: 19, scope: !64) +// CHECK:STDOUT: !73 = !DILocation(line: 19, column: 11, scope: !64) +// CHECK:STDOUT: !74 = !DILocation(line: 19, column: 10, scope: !64) +// CHECK:STDOUT: !75 = !DILocation(line: 20, column: 9, scope: !64) +// CHECK:STDOUT: !76 = !DILocation(line: 21, column: 38, scope: !64) +// CHECK:STDOUT: !77 = !DILocation(line: 21, column: 16, scope: !64) +// CHECK:STDOUT: !78 = !DILocation(line: 21, column: 9, scope: !64) +// CHECK:STDOUT: !79 = !DILocation(line: 23, column: 16, scope: !64) +// CHECK:STDOUT: !80 = !DILocation(line: 23, column: 9, scope: !64) // CHECK:STDOUT: !81 = distinct !DISubprogram(name: "HasValue", linkageName: "_CHasValue.Optional.Core.329ac87584bc77f7", scope: null, file: !82, line: 36, type: !83, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !85) // CHECK:STDOUT: !82 = !DIFile(filename: "{{.*}}/prelude/types/optional.carbon", directory: "") // CHECK:STDOUT: !83 = !DISubroutineType(types: !84) diff --git a/toolchain/lower/testdata/for/for.carbon b/toolchain/lower/testdata/for/for.carbon index c8a8dd6048a2..66cdab5f47dc 100644 --- a/toolchain/lower/testdata/for/for.carbon +++ b/toolchain/lower/testdata/for/for.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -37,33 +38,33 @@ fn For() { // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define void @_CFor.Main() #0 !dbg !4 { // CHECK:STDOUT: entry: -// CHECK:STDOUT: %.loc21_32.1.temp = alloca { i32, i32 }, align 4, !dbg !7 +// CHECK:STDOUT: %.loc22_32.1.temp = alloca { i32, i32 }, align 4, !dbg !7 // CHECK:STDOUT: %var = alloca i32, align 4, !dbg !8 -// CHECK:STDOUT: %.loc21_33.1.temp = alloca <{ i32, i1 }>, align 4, !dbg !8 +// CHECK:STDOUT: %.loc22_33.1.temp = alloca <{ i32, i1 }>, align 4, !dbg !8 // CHECK:STDOUT: call void @_CF.Main(), !dbg !9 -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc21_32.1.temp), !dbg !7 -// CHECK:STDOUT: call void @_CRange.Core(ptr %.loc21_32.1.temp, i32 100), !dbg !7 -// CHECK:STDOUT: %IntRange.as.Iterate.impl.NewCursor.call = call i32 @"_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc21_32.1.temp), !dbg !8 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc22_32.1.temp), !dbg !7 +// CHECK:STDOUT: call void @_CRange.Core(ptr %.loc22_32.1.temp, i32 100), !dbg !7 +// CHECK:STDOUT: %IntRange.as.Iterate.impl.NewCursor.call = call i32 @"_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc22_32.1.temp), !dbg !8 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %var), !dbg !8 // CHECK:STDOUT: store i32 %IntRange.as.Iterate.impl.NewCursor.call, ptr %var, align 4, !dbg !8 // CHECK:STDOUT: br label %for.next, !dbg !8 // CHECK:STDOUT: // CHECK:STDOUT: for.next: ; preds = %for.body, %entry -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc21_33.1.temp), !dbg !8 -// CHECK:STDOUT: call void @"_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc21_33.1.temp, ptr %.loc21_32.1.temp, ptr %var), !dbg !8 -// CHECK:STDOUT: %Optional.HasValue.call = call i1 @_CHasValue.Optional.Core.329ac87584bc77f7(ptr %.loc21_33.1.temp), !dbg !8 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc22_33.1.temp), !dbg !8 +// CHECK:STDOUT: call void @"_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8"(ptr %.loc22_33.1.temp, ptr %.loc22_32.1.temp, ptr %var), !dbg !8 +// CHECK:STDOUT: %Optional.HasValue.call = call i1 @_CHasValue.Optional.Core.329ac87584bc77f7(ptr %.loc22_33.1.temp), !dbg !8 // CHECK:STDOUT: br i1 %Optional.HasValue.call, label %for.body, label %for.done, !dbg !8 // CHECK:STDOUT: // CHECK:STDOUT: for.body: ; preds = %for.next -// CHECK:STDOUT: %Optional.Get.call = call i32 @_CGet.Optional.Core.329ac87584bc77f7(ptr %.loc21_33.1.temp), !dbg !8 +// CHECK:STDOUT: %Optional.Get.call = call i32 @_CGet.Optional.Core.329ac87584bc77f7(ptr %.loc22_33.1.temp), !dbg !8 // CHECK:STDOUT: call void @_CG.Main(), !dbg !10 -// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc21_33.1.temp), !dbg !8 +// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc22_33.1.temp), !dbg !8 // CHECK:STDOUT: br label %for.next, !dbg !11 // CHECK:STDOUT: // CHECK:STDOUT: for.done: ; preds = %for.next -// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc21_33.1.temp), !dbg !8 +// CHECK:STDOUT: call void @"_COp.f9d363db90f1ff8b:core.Destroy.Core"(ptr %.loc22_33.1.temp), !dbg !8 // CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %var), !dbg !8 -// CHECK:STDOUT: call void @"_COp.0d5da2659ce22e5f:core.Destroy.Core"(ptr %.loc21_32.1.temp), !dbg !7 +// CHECK:STDOUT: call void @"_COp.0d5da2659ce22e5f:core.Destroy.Core"(ptr %.loc22_32.1.temp), !dbg !7 // CHECK:STDOUT: call void @_CH.Main(), !dbg !12 // CHECK:STDOUT: ret void, !dbg !13 // CHECK:STDOUT: } @@ -255,79 +256,79 @@ fn For() { // CHECK:STDOUT: !1 = !DIFile(filename: "for.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "For", linkageName: "_CFor.Main", scope: null, file: !1, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "For", linkageName: "_CFor.Main", scope: null, file: !1, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{null} -// CHECK:STDOUT: !7 = !DILocation(line: 21, column: 18, scope: !4) -// CHECK:STDOUT: !8 = !DILocation(line: 21, column: 7, scope: !4) -// CHECK:STDOUT: !9 = !DILocation(line: 20, column: 3, scope: !4) -// CHECK:STDOUT: !10 = !DILocation(line: 22, column: 5, scope: !4) -// CHECK:STDOUT: !11 = !DILocation(line: 21, column: 3, scope: !4) -// CHECK:STDOUT: !12 = !DILocation(line: 24, column: 3, scope: !4) -// CHECK:STDOUT: !13 = !DILocation(line: 19, column: 1, scope: !4) -// CHECK:STDOUT: !14 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !15, line: 24, type: !16, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !19) +// CHECK:STDOUT: !7 = !DILocation(line: 22, column: 18, scope: !4) +// CHECK:STDOUT: !8 = !DILocation(line: 22, column: 7, scope: !4) +// CHECK:STDOUT: !9 = !DILocation(line: 21, column: 3, scope: !4) +// CHECK:STDOUT: !10 = !DILocation(line: 23, column: 5, scope: !4) +// CHECK:STDOUT: !11 = !DILocation(line: 22, column: 3, scope: !4) +// CHECK:STDOUT: !12 = !DILocation(line: 25, column: 3, scope: !4) +// CHECK:STDOUT: !13 = !DILocation(line: 20, column: 1, scope: !4) +// CHECK:STDOUT: !14 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !15, line: 15, type: !16, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !19) // CHECK:STDOUT: !15 = !DIFile(filename: "{{.*}}/range.carbon", directory: "") // CHECK:STDOUT: !16 = !DISubroutineType(types: !17) // CHECK:STDOUT: !17 = !{null, !18} // CHECK:STDOUT: !18 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) // CHECK:STDOUT: !19 = !{!20} // CHECK:STDOUT: !20 = !DILocalVariable(arg: 1, scope: !14, type: !18) -// CHECK:STDOUT: !21 = !DILocation(line: 24, column: 39, scope: !14) -// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "Op", linkageName: "_COp.94ba1c30d421702e:core.Destroy.Core", scope: null, file: !1, line: 21, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !26) +// CHECK:STDOUT: !21 = !DILocation(line: 15, column: 39, scope: !14) +// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "Op", linkageName: "_COp.94ba1c30d421702e:core.Destroy.Core", scope: null, file: !1, line: 22, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !26) // CHECK:STDOUT: !23 = !DISubroutineType(types: !24) // CHECK:STDOUT: !24 = !{null, !25} // CHECK:STDOUT: !25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) // CHECK:STDOUT: !26 = !{!27} // CHECK:STDOUT: !27 = !DILocalVariable(arg: 1, scope: !22, type: !25) -// CHECK:STDOUT: !28 = !DILocation(line: 21, column: 7, scope: !22) -// CHECK:STDOUT: !29 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0fc9634857315db2:core.Destroy.Core", scope: null, file: !1, line: 21, type: !16, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !30) +// CHECK:STDOUT: !28 = !DILocation(line: 22, column: 7, scope: !22) +// CHECK:STDOUT: !29 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0fc9634857315db2:core.Destroy.Core", scope: null, file: !1, line: 22, type: !16, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !30) // CHECK:STDOUT: !30 = !{!31} // CHECK:STDOUT: !31 = !DILocalVariable(arg: 1, scope: !29, type: !18) -// CHECK:STDOUT: !32 = !DILocation(line: 21, column: 7, scope: !29) -// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.69700c1fc1b2744c:core.Destroy.Core", scope: null, file: !1, line: 21, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !34) +// CHECK:STDOUT: !32 = !DILocation(line: 22, column: 7, scope: !29) +// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.69700c1fc1b2744c:core.Destroy.Core", scope: null, file: !1, line: 22, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !34) // CHECK:STDOUT: !34 = !{!35} // CHECK:STDOUT: !35 = !DILocalVariable(arg: 1, scope: !33, type: !25) -// CHECK:STDOUT: !36 = !DILocation(line: 21, column: 7, scope: !33) -// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "Op", linkageName: "_COp.278d9a31079e7ff2:core.Destroy.Core", scope: null, file: !1, line: 21, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !38) +// CHECK:STDOUT: !36 = !DILocation(line: 22, column: 7, scope: !33) +// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "Op", linkageName: "_COp.278d9a31079e7ff2:core.Destroy.Core", scope: null, file: !1, line: 22, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !38) // CHECK:STDOUT: !38 = !{!39} // CHECK:STDOUT: !39 = !DILocalVariable(arg: 1, scope: !37, type: !25) -// CHECK:STDOUT: !40 = !DILocation(line: 21, column: 7, scope: !37) -// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "Op", linkageName: "_COp.f9d363db90f1ff8b:core.Destroy.Core", scope: null, file: !1, line: 21, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !42) +// CHECK:STDOUT: !40 = !DILocation(line: 22, column: 7, scope: !37) +// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "Op", linkageName: "_COp.f9d363db90f1ff8b:core.Destroy.Core", scope: null, file: !1, line: 22, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !42) // CHECK:STDOUT: !42 = !{!43} // CHECK:STDOUT: !43 = !DILocalVariable(arg: 1, scope: !41, type: !25) -// CHECK:STDOUT: !44 = !DILocation(line: 21, column: 7, scope: !41) -// CHECK:STDOUT: !45 = distinct !DISubprogram(name: "Op", linkageName: "_COp.db43fa38232c28dd:core.Destroy.Core", scope: null, file: !1, line: 21, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !46) +// CHECK:STDOUT: !44 = !DILocation(line: 22, column: 7, scope: !41) +// CHECK:STDOUT: !45 = distinct !DISubprogram(name: "Op", linkageName: "_COp.db43fa38232c28dd:core.Destroy.Core", scope: null, file: !1, line: 22, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !46) // CHECK:STDOUT: !46 = !{!47} // CHECK:STDOUT: !47 = !DILocalVariable(arg: 1, scope: !45, type: !25) -// CHECK:STDOUT: !48 = !DILocation(line: 21, column: 18, scope: !45) -// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0d5da2659ce22e5f:core.Destroy.Core", scope: null, file: !1, line: 21, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !50) +// CHECK:STDOUT: !48 = !DILocation(line: 22, column: 18, scope: !45) +// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Op", linkageName: "_COp.0d5da2659ce22e5f:core.Destroy.Core", scope: null, file: !1, line: 22, type: !23, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !50) // CHECK:STDOUT: !50 = !{!51} // CHECK:STDOUT: !51 = !DILocalVariable(arg: 1, scope: !49, type: !25) -// CHECK:STDOUT: !52 = !DILocation(line: 21, column: 18, scope: !49) -// CHECK:STDOUT: !53 = distinct !DISubprogram(name: "NewCursor", linkageName: "_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !15, line: 25, type: !54, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !56) +// CHECK:STDOUT: !52 = !DILocation(line: 22, column: 18, scope: !49) +// CHECK:STDOUT: !53 = distinct !DISubprogram(name: "NewCursor", linkageName: "_CNewCursor.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !15, line: 16, type: !54, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !56) // CHECK:STDOUT: !54 = !DISubroutineType(types: !55) // CHECK:STDOUT: !55 = !{!18, !25} // CHECK:STDOUT: !56 = !{!57} // CHECK:STDOUT: !57 = !DILocalVariable(arg: 1, scope: !53, type: !25) -// CHECK:STDOUT: !58 = !DILocation(line: 25, column: 43, scope: !53) -// CHECK:STDOUT: !59 = !DILocation(line: 25, column: 36, scope: !53) -// CHECK:STDOUT: !60 = distinct !DISubprogram(name: "Next", linkageName: "_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !15, line: 26, type: !61, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !63) +// CHECK:STDOUT: !58 = !DILocation(line: 16, column: 43, scope: !53) +// CHECK:STDOUT: !59 = !DILocation(line: 16, column: 36, scope: !53) +// CHECK:STDOUT: !60 = distinct !DISubprogram(name: "Next", linkageName: "_CNext.IntRange.9452f4c51951679b.Core:Iterate.Core.be1e879c1ad406d8", scope: null, file: !15, line: 17, type: !61, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !63) // CHECK:STDOUT: !61 = !DISubroutineType(types: !62) // CHECK:STDOUT: !62 = !{!25, !25, !25} // CHECK:STDOUT: !63 = !{!64, !65} // CHECK:STDOUT: !64 = !DILocalVariable(arg: 1, scope: !60, type: !25) // CHECK:STDOUT: !65 = !DILocalVariable(arg: 2, scope: !60, type: !25) -// CHECK:STDOUT: !66 = !DILocation(line: 27, column: 7, scope: !60) -// CHECK:STDOUT: !67 = !DILocation(line: 27, column: 27, scope: !60) -// CHECK:STDOUT: !68 = !DILocation(line: 28, column: 19, scope: !60) -// CHECK:STDOUT: !69 = !DILocation(line: 28, column: 11, scope: !60) -// CHECK:STDOUT: !70 = !DILocation(line: 28, column: 10, scope: !60) -// CHECK:STDOUT: !71 = !DILocation(line: 29, column: 9, scope: !60) -// CHECK:STDOUT: !72 = !DILocation(line: 30, column: 38, scope: !60) -// CHECK:STDOUT: !73 = !DILocation(line: 30, column: 16, scope: !60) -// CHECK:STDOUT: !74 = !DILocation(line: 30, column: 9, scope: !60) -// CHECK:STDOUT: !75 = !DILocation(line: 32, column: 16, scope: !60) -// CHECK:STDOUT: !76 = !DILocation(line: 32, column: 9, scope: !60) +// CHECK:STDOUT: !66 = !DILocation(line: 18, column: 7, scope: !60) +// CHECK:STDOUT: !67 = !DILocation(line: 18, column: 27, scope: !60) +// CHECK:STDOUT: !68 = !DILocation(line: 19, column: 19, scope: !60) +// CHECK:STDOUT: !69 = !DILocation(line: 19, column: 11, scope: !60) +// CHECK:STDOUT: !70 = !DILocation(line: 19, column: 10, scope: !60) +// CHECK:STDOUT: !71 = !DILocation(line: 20, column: 9, scope: !60) +// CHECK:STDOUT: !72 = !DILocation(line: 21, column: 38, scope: !60) +// CHECK:STDOUT: !73 = !DILocation(line: 21, column: 16, scope: !60) +// CHECK:STDOUT: !74 = !DILocation(line: 21, column: 9, scope: !60) +// CHECK:STDOUT: !75 = !DILocation(line: 23, column: 16, scope: !60) +// CHECK:STDOUT: !76 = !DILocation(line: 23, column: 9, scope: !60) // CHECK:STDOUT: !77 = distinct !DISubprogram(name: "HasValue", linkageName: "_CHasValue.Optional.Core.329ac87584bc77f7", scope: null, file: !78, line: 36, type: !79, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !81) // CHECK:STDOUT: !78 = !DIFile(filename: "{{.*}}/prelude/types/optional.carbon", directory: "") // CHECK:STDOUT: !79 = !DISubroutineType(types: !80) diff --git a/toolchain/lower/testdata/function/generic/call_different_impls.carbon b/toolchain/lower/testdata/function/generic/call_different_impls.carbon index f5c5f5585430..bbc339bc0f02 100644 --- a/toolchain/lower/testdata/function/generic/call_different_impls.carbon +++ b/toolchain/lower/testdata/function/generic/call_different_impls.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -89,25 +90,25 @@ fn Run() { // CHECK:STDOUT: !1 = !DIFile(filename: "call_different_impls.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.X.Main:I.Main", scope: null, file: !1, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.X.Main:I.Main", scope: null, file: !1, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{null} -// CHECK:STDOUT: !7 = !DILocation(line: 20, column: 12, scope: !4) -// CHECK:STDOUT: !8 = !DILocation(line: 20, column: 3, scope: !4) -// CHECK:STDOUT: !9 = distinct !DISubprogram(name: "F", linkageName: "_CF.Y.Main:I.Main", scope: null, file: !1, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !0) -// CHECK:STDOUT: !10 = !DILocation(line: 24, column: 12, scope: !9) -// CHECK:STDOUT: !11 = !DILocation(line: 24, column: 3, scope: !9) -// CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !1, line: 31, type: !13, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !7 = !DILocation(line: 21, column: 12, scope: !4) +// CHECK:STDOUT: !8 = !DILocation(line: 21, column: 3, scope: !4) +// CHECK:STDOUT: !9 = distinct !DISubprogram(name: "F", linkageName: "_CF.Y.Main:I.Main", scope: null, file: !1, line: 25, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !10 = !DILocation(line: 25, column: 12, scope: !9) +// CHECK:STDOUT: !11 = !DILocation(line: 25, column: 3, scope: !9) +// CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !1, line: 32, type: !13, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !13 = !DISubroutineType(types: !14) // CHECK:STDOUT: !14 = !{!15} // CHECK:STDOUT: !15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -// CHECK:STDOUT: !16 = !DILocation(line: 32, column: 3, scope: !12) -// CHECK:STDOUT: !17 = !DILocation(line: 33, column: 3, scope: !12) -// CHECK:STDOUT: !18 = !DILocation(line: 31, column: 1, scope: !12) -// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c81631f865470482", scope: null, file: !1, line: 29, type: !5, spFlags: DISPFlagDefinition, unit: !0) -// CHECK:STDOUT: !20 = !DILocation(line: 29, column: 22, scope: !19) -// CHECK:STDOUT: !21 = !DILocation(line: 29, column: 1, scope: !19) -// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.0b241ec84a68877b", scope: null, file: !1, line: 29, type: !5, spFlags: DISPFlagDefinition, unit: !0) -// CHECK:STDOUT: !23 = !DILocation(line: 29, column: 22, scope: !22) -// CHECK:STDOUT: !24 = !DILocation(line: 29, column: 1, scope: !22) +// CHECK:STDOUT: !16 = !DILocation(line: 33, column: 3, scope: !12) +// CHECK:STDOUT: !17 = !DILocation(line: 34, column: 3, scope: !12) +// CHECK:STDOUT: !18 = !DILocation(line: 32, column: 1, scope: !12) +// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c81631f865470482", scope: null, file: !1, line: 30, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !20 = !DILocation(line: 30, column: 22, scope: !19) +// CHECK:STDOUT: !21 = !DILocation(line: 30, column: 1, scope: !19) +// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.0b241ec84a68877b", scope: null, file: !1, line: 30, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !23 = !DILocation(line: 30, column: 22, scope: !22) +// CHECK:STDOUT: !24 = !DILocation(line: 30, column: 1, scope: !22) // CHECK:STDOUT: diff --git a/toolchain/lower/testdata/function/generic/call_different_impls_with_const.carbon b/toolchain/lower/testdata/function/generic/call_different_impls_with_const.carbon index 60e6be94dc30..4cdb373967df 100644 --- a/toolchain/lower/testdata/function/generic/call_different_impls_with_const.carbon +++ b/toolchain/lower/testdata/function/generic/call_different_impls_with_const.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -81,25 +82,25 @@ fn Run() { // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define linkonce_odr void @_CG.Main.e2c7a58ecf9ad23e() #0 !dbg !26 { // CHECK:STDOUT: entry: -// CHECK:STDOUT: %.loc37_20.1.temp = alloca i1, align 1, !dbg !29 -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc37_20.1.temp), !dbg !29 +// CHECK:STDOUT: %.loc38_20.1.temp = alloca i1, align 1, !dbg !29 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc38_20.1.temp), !dbg !29 // CHECK:STDOUT: %I.WithSelf.F.call = call i1 @"_CF.X.Main:I.Main"(), !dbg !29 -// CHECK:STDOUT: %.loc37_20.2 = zext i1 %I.WithSelf.F.call to i8, !dbg !29 -// CHECK:STDOUT: store i8 %.loc37_20.2, ptr %.loc37_20.1.temp, align 1, !dbg !29 -// CHECK:STDOUT: %.loc37_20.3 = load i8, ptr %.loc37_20.1.temp, align 1, !dbg !29 -// CHECK:STDOUT: %.loc37_20.31 = trunc i8 %.loc37_20.3 to i1, !dbg !29 +// CHECK:STDOUT: %.loc38_20.2 = zext i1 %I.WithSelf.F.call to i8, !dbg !29 +// CHECK:STDOUT: store i8 %.loc38_20.2, ptr %.loc38_20.1.temp, align 1, !dbg !29 +// CHECK:STDOUT: %.loc38_20.3 = load i8, ptr %.loc38_20.1.temp, align 1, !dbg !29 +// CHECK:STDOUT: %.loc38_20.31 = trunc i8 %.loc38_20.3 to i1, !dbg !29 // CHECK:STDOUT: ret void, !dbg !30 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define linkonce_odr void @_CG.Main.01a101e5421592ac() #0 !dbg !31 { // CHECK:STDOUT: entry: -// CHECK:STDOUT: %.loc37_20.1.temp = alloca i32, align 4, !dbg !32 -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc37_20.1.temp), !dbg !32 +// CHECK:STDOUT: %.loc38_20.1.temp = alloca i32, align 4, !dbg !32 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc38_20.1.temp), !dbg !32 // CHECK:STDOUT: %I.WithSelf.F.call = call i32 @"_CF.Y.Main:I.Main"(), !dbg !32 -// CHECK:STDOUT: store i32 %I.WithSelf.F.call, ptr %.loc37_20.1.temp, align 4, !dbg !32 -// CHECK:STDOUT: %.loc37_20.3 = load i32, ptr %.loc37_20.1.temp, align 4, !dbg !32 -// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %.loc37_20.1.temp), !dbg !32 +// CHECK:STDOUT: store i32 %I.WithSelf.F.call, ptr %.loc38_20.1.temp, align 4, !dbg !32 +// CHECK:STDOUT: %.loc38_20.3 = load i32, ptr %.loc38_20.1.temp, align 4, !dbg !32 +// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %.loc38_20.1.temp), !dbg !32 // CHECK:STDOUT: ret void, !dbg !33 // CHECK:STDOUT: } // CHECK:STDOUT: @@ -120,34 +121,34 @@ fn Run() { // CHECK:STDOUT: !1 = !DIFile(filename: "call_different_impls_with_const.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.X.Main:I.Main", scope: null, file: !1, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.X.Main:I.Main", scope: null, file: !1, line: 22, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{!7} // CHECK:STDOUT: !7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) -// CHECK:STDOUT: !8 = !DILocation(line: 22, column: 5, scope: !4) -// CHECK:STDOUT: !9 = !DILocation(line: 23, column: 5, scope: !4) -// CHECK:STDOUT: !10 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 27, type: !11, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14) +// CHECK:STDOUT: !8 = !DILocation(line: 23, column: 5, scope: !4) +// CHECK:STDOUT: !9 = !DILocation(line: 24, column: 5, scope: !4) +// CHECK:STDOUT: !10 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 28, type: !11, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14) // CHECK:STDOUT: !11 = !DISubroutineType(types: !12) // CHECK:STDOUT: !12 = !{null, !13} // CHECK:STDOUT: !13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) // CHECK:STDOUT: !14 = !{!15} // CHECK:STDOUT: !15 = !DILocalVariable(arg: 1, scope: !10, type: !13) -// CHECK:STDOUT: !16 = !DILocation(line: 27, column: 24, scope: !10) -// CHECK:STDOUT: !17 = distinct !DISubprogram(name: "F", linkageName: "_CF.Y.Main:I.Main", scope: null, file: !1, line: 28, type: !18, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !16 = !DILocation(line: 28, column: 24, scope: !10) +// CHECK:STDOUT: !17 = distinct !DISubprogram(name: "F", linkageName: "_CF.Y.Main:I.Main", scope: null, file: !1, line: 29, type: !18, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !18 = !DISubroutineType(types: !19) // CHECK:STDOUT: !19 = !{!13} -// CHECK:STDOUT: !20 = !DILocation(line: 29, column: 5, scope: !17) -// CHECK:STDOUT: !21 = !DILocation(line: 30, column: 5, scope: !17) -// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !1, line: 40, type: !18, spFlags: DISPFlagDefinition, unit: !0) -// CHECK:STDOUT: !23 = !DILocation(line: 41, column: 3, scope: !22) -// CHECK:STDOUT: !24 = !DILocation(line: 42, column: 3, scope: !22) -// CHECK:STDOUT: !25 = !DILocation(line: 40, column: 1, scope: !22) -// CHECK:STDOUT: !26 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e2c7a58ecf9ad23e", scope: null, file: !1, line: 36, type: !27, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !20 = !DILocation(line: 30, column: 5, scope: !17) +// CHECK:STDOUT: !21 = !DILocation(line: 31, column: 5, scope: !17) +// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !1, line: 41, type: !18, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !23 = !DILocation(line: 42, column: 3, scope: !22) +// CHECK:STDOUT: !24 = !DILocation(line: 43, column: 3, scope: !22) +// CHECK:STDOUT: !25 = !DILocation(line: 41, column: 1, scope: !22) +// CHECK:STDOUT: !26 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e2c7a58ecf9ad23e", scope: null, file: !1, line: 37, type: !27, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !27 = !DISubroutineType(types: !28) // CHECK:STDOUT: !28 = !{null} -// CHECK:STDOUT: !29 = !DILocation(line: 37, column: 16, scope: !26) -// CHECK:STDOUT: !30 = !DILocation(line: 36, column: 1, scope: !26) -// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.01a101e5421592ac", scope: null, file: !1, line: 36, type: !27, spFlags: DISPFlagDefinition, unit: !0) -// CHECK:STDOUT: !32 = !DILocation(line: 37, column: 16, scope: !31) -// CHECK:STDOUT: !33 = !DILocation(line: 36, column: 1, scope: !31) +// CHECK:STDOUT: !29 = !DILocation(line: 38, column: 16, scope: !26) +// CHECK:STDOUT: !30 = !DILocation(line: 37, column: 1, scope: !26) +// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.01a101e5421592ac", scope: null, file: !1, line: 37, type: !27, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !32 = !DILocation(line: 38, column: 16, scope: !31) +// CHECK:STDOUT: !33 = !DILocation(line: 37, column: 1, scope: !31) // CHECK:STDOUT: diff --git a/toolchain/lower/testdata/function/generic/call_recursive_diamond.carbon b/toolchain/lower/testdata/function/generic/call_recursive_diamond.carbon index a925f6407553..c77ecfe2e9e1 100644 --- a/toolchain/lower/testdata/function/generic/call_recursive_diamond.carbon +++ b/toolchain/lower/testdata/function/generic/call_recursive_diamond.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -77,14 +78,14 @@ fn M() { // CHECK:STDOUT: store ptr %n.var, ptr %ptr_i32.var, align 8, !dbg !9 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_f64.var), !dbg !10 // CHECK:STDOUT: store ptr %m.var, ptr %ptr_f64.var, align 8, !dbg !10 -// CHECK:STDOUT: %.loc53_5 = load i32, ptr %n.var, align 4, !dbg !11 -// CHECK:STDOUT: %A.call.loc53 = call i32 @_CA.Main.5bd8d5767580997a(i32 %.loc53_5, i32 0), !dbg !12 -// CHECK:STDOUT: %.loc54_5 = load double, ptr %m.var, align 8, !dbg !13 -// CHECK:STDOUT: %A.call.loc54 = call double @_CA.Main.c27b765f2159c9a0(double %.loc54_5, i32 0), !dbg !14 -// CHECK:STDOUT: %.loc55_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15 -// CHECK:STDOUT: %A.call.loc55 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc55_5, i32 0), !dbg !16 -// CHECK:STDOUT: %.loc56_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17 -// CHECK:STDOUT: %A.call.loc56 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc56_5, i32 0), !dbg !18 +// CHECK:STDOUT: %.loc54_5 = load i32, ptr %n.var, align 4, !dbg !11 +// CHECK:STDOUT: %A.call.loc54 = call i32 @_CA.Main.5bd8d5767580997a(i32 %.loc54_5, i32 0), !dbg !12 +// CHECK:STDOUT: %.loc55_5 = load double, ptr %m.var, align 8, !dbg !13 +// CHECK:STDOUT: %A.call.loc55 = call double @_CA.Main.c27b765f2159c9a0(double %.loc55_5, i32 0), !dbg !14 +// CHECK:STDOUT: %.loc56_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15 +// CHECK:STDOUT: %A.call.loc56 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc56_5, i32 0), !dbg !16 +// CHECK:STDOUT: %.loc57_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17 +// CHECK:STDOUT: %A.call.loc57 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc57_5, i32 0), !dbg !18 // CHECK:STDOUT: call void @"_COp.30d8007fdcc57f83:core.Destroy.Core"(ptr %m.var), !dbg !8 // CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %n.var), !dbg !7 // CHECK:STDOUT: ret void, !dbg !19 @@ -109,21 +110,21 @@ fn M() { // CHECK:STDOUT: define linkonce_odr i32 @_CA.Main.5bd8d5767580997a(i32 %x, i32 %count) #0 !dbg !34 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %Int.as.OrderedWith.impl.Greater.call = icmp sgt i32 %count, 4, !dbg !40 -// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc22, label %if.else.loc22, !dbg !41 +// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc23, label %if.else.loc23, !dbg !41 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc22: ; preds = %entry +// CHECK:STDOUT: if.then.loc23: ; preds = %entry // CHECK:STDOUT: ret i32 %x, !dbg !42 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc22: ; preds = %entry +// CHECK:STDOUT: if.else.loc23: ; preds = %entry // CHECK:STDOUT: %Int.as.ModWith.impl.Op.call = srem i32 %count, 2, !dbg !43 // CHECK:STDOUT: %Int.as.EqWith.impl.Equal.call = icmp eq i32 %Int.as.ModWith.impl.Op.call, 0, !dbg !43 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc25, label %if.else.loc25, !dbg !44 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc26, label %if.else.loc26, !dbg !44 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc25: ; preds = %if.else.loc22 +// CHECK:STDOUT: if.then.loc26: ; preds = %if.else.loc23 // CHECK:STDOUT: %B.call = call i32 @_CB.Main.5bd8d5767580997a(i32 %x, i32 %count), !dbg !45 // CHECK:STDOUT: ret i32 %B.call, !dbg !46 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc25: ; preds = %if.else.loc22 +// CHECK:STDOUT: if.else.loc26: ; preds = %if.else.loc23 // CHECK:STDOUT: %C.call = call i32 @_CC.Main.5bd8d5767580997a(i32 %x, i32 %count), !dbg !47 // CHECK:STDOUT: ret i32 %C.call, !dbg !48 // CHECK:STDOUT: } @@ -132,21 +133,21 @@ fn M() { // CHECK:STDOUT: define linkonce_odr double @_CA.Main.c27b765f2159c9a0(double %x, i32 %count) #0 !dbg !49 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %Int.as.OrderedWith.impl.Greater.call = icmp sgt i32 %count, 4, !dbg !55 -// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc22, label %if.else.loc22, !dbg !56 +// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc23, label %if.else.loc23, !dbg !56 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc22: ; preds = %entry +// CHECK:STDOUT: if.then.loc23: ; preds = %entry // CHECK:STDOUT: ret double %x, !dbg !57 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc22: ; preds = %entry +// CHECK:STDOUT: if.else.loc23: ; preds = %entry // CHECK:STDOUT: %Int.as.ModWith.impl.Op.call = srem i32 %count, 2, !dbg !58 // CHECK:STDOUT: %Int.as.EqWith.impl.Equal.call = icmp eq i32 %Int.as.ModWith.impl.Op.call, 0, !dbg !58 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc25, label %if.else.loc25, !dbg !59 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc26, label %if.else.loc26, !dbg !59 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc25: ; preds = %if.else.loc22 +// CHECK:STDOUT: if.then.loc26: ; preds = %if.else.loc23 // CHECK:STDOUT: %B.call = call double @_CB.Main.c27b765f2159c9a0(double %x, i32 %count), !dbg !60 // CHECK:STDOUT: ret double %B.call, !dbg !61 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc25: ; preds = %if.else.loc22 +// CHECK:STDOUT: if.else.loc26: ; preds = %if.else.loc23 // CHECK:STDOUT: %C.call = call double @_CC.Main.c27b765f2159c9a0(double %x, i32 %count), !dbg !62 // CHECK:STDOUT: ret double %C.call, !dbg !63 // CHECK:STDOUT: } @@ -155,21 +156,21 @@ fn M() { // CHECK:STDOUT: define linkonce_odr ptr @_CA.Main.2621742a01881e29(ptr %x, i32 %count) #0 !dbg !64 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %Int.as.OrderedWith.impl.Greater.call = icmp sgt i32 %count, 4, !dbg !68 -// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc22, label %if.else.loc22, !dbg !69 +// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc23, label %if.else.loc23, !dbg !69 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc22: ; preds = %entry +// CHECK:STDOUT: if.then.loc23: ; preds = %entry // CHECK:STDOUT: ret ptr %x, !dbg !70 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc22: ; preds = %entry +// CHECK:STDOUT: if.else.loc23: ; preds = %entry // CHECK:STDOUT: %Int.as.ModWith.impl.Op.call = srem i32 %count, 2, !dbg !71 // CHECK:STDOUT: %Int.as.EqWith.impl.Equal.call = icmp eq i32 %Int.as.ModWith.impl.Op.call, 0, !dbg !71 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc25, label %if.else.loc25, !dbg !72 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc26, label %if.else.loc26, !dbg !72 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc25: ; preds = %if.else.loc22 +// CHECK:STDOUT: if.then.loc26: ; preds = %if.else.loc23 // CHECK:STDOUT: %B.call = call ptr @_CB.Main.2621742a01881e29(ptr %x, i32 %count), !dbg !73 // CHECK:STDOUT: ret ptr %B.call, !dbg !74 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc25: ; preds = %if.else.loc22 +// CHECK:STDOUT: if.else.loc26: ; preds = %if.else.loc23 // CHECK:STDOUT: %C.call = call ptr @_CC.Main.2621742a01881e29(ptr %x, i32 %count), !dbg !75 // CHECK:STDOUT: ret ptr %C.call, !dbg !76 // CHECK:STDOUT: } @@ -266,140 +267,140 @@ fn M() { // CHECK:STDOUT: !1 = !DIFile(filename: "call_recursive_diamond.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !1, line: 47, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !1, line: 48, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{null} -// CHECK:STDOUT: !7 = !DILocation(line: 48, column: 3, scope: !4) -// CHECK:STDOUT: !8 = !DILocation(line: 49, column: 3, scope: !4) -// CHECK:STDOUT: !9 = !DILocation(line: 50, column: 3, scope: !4) -// CHECK:STDOUT: !10 = !DILocation(line: 51, column: 3, scope: !4) -// CHECK:STDOUT: !11 = !DILocation(line: 53, column: 5, scope: !4) -// CHECK:STDOUT: !12 = !DILocation(line: 53, column: 3, scope: !4) -// CHECK:STDOUT: !13 = !DILocation(line: 54, column: 5, scope: !4) -// CHECK:STDOUT: !14 = !DILocation(line: 54, column: 3, scope: !4) -// CHECK:STDOUT: !15 = !DILocation(line: 55, column: 5, scope: !4) -// CHECK:STDOUT: !16 = !DILocation(line: 55, column: 3, scope: !4) -// CHECK:STDOUT: !17 = !DILocation(line: 56, column: 5, scope: !4) -// CHECK:STDOUT: !18 = !DILocation(line: 56, column: 3, scope: !4) -// CHECK:STDOUT: !19 = !DILocation(line: 47, column: 1, scope: !4) -// CHECK:STDOUT: !20 = distinct !DISubprogram(name: "Op", linkageName: "_COp.30d8007fdcc57f83:core.Destroy.Core", scope: null, file: !1, line: 49, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !24) +// CHECK:STDOUT: !7 = !DILocation(line: 49, column: 3, scope: !4) +// CHECK:STDOUT: !8 = !DILocation(line: 50, column: 3, scope: !4) +// CHECK:STDOUT: !9 = !DILocation(line: 51, column: 3, scope: !4) +// CHECK:STDOUT: !10 = !DILocation(line: 52, column: 3, scope: !4) +// CHECK:STDOUT: !11 = !DILocation(line: 54, column: 5, scope: !4) +// CHECK:STDOUT: !12 = !DILocation(line: 54, column: 3, scope: !4) +// CHECK:STDOUT: !13 = !DILocation(line: 55, column: 5, scope: !4) +// CHECK:STDOUT: !14 = !DILocation(line: 55, column: 3, scope: !4) +// CHECK:STDOUT: !15 = !DILocation(line: 56, column: 5, scope: !4) +// CHECK:STDOUT: !16 = !DILocation(line: 56, column: 3, scope: !4) +// CHECK:STDOUT: !17 = !DILocation(line: 57, column: 5, scope: !4) +// CHECK:STDOUT: !18 = !DILocation(line: 57, column: 3, scope: !4) +// CHECK:STDOUT: !19 = !DILocation(line: 48, column: 1, scope: !4) +// CHECK:STDOUT: !20 = distinct !DISubprogram(name: "Op", linkageName: "_COp.30d8007fdcc57f83:core.Destroy.Core", scope: null, file: !1, line: 50, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !24) // CHECK:STDOUT: !21 = !DISubroutineType(types: !22) // CHECK:STDOUT: !22 = !{null, !23} // CHECK:STDOUT: !23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) // CHECK:STDOUT: !24 = !{!25} // CHECK:STDOUT: !25 = !DILocalVariable(arg: 1, scope: !20, type: !23) -// CHECK:STDOUT: !26 = !DILocation(line: 49, column: 3, scope: !20) -// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 48, type: !28, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !31) +// CHECK:STDOUT: !26 = !DILocation(line: 50, column: 3, scope: !20) +// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 49, type: !28, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !31) // CHECK:STDOUT: !28 = !DISubroutineType(types: !29) // CHECK:STDOUT: !29 = !{null, !30} // CHECK:STDOUT: !30 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) // CHECK:STDOUT: !31 = !{!32} // CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !27, type: !30) -// CHECK:STDOUT: !33 = !DILocation(line: 48, column: 3, scope: !27) -// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.5bd8d5767580997a", scope: null, file: !1, line: 21, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !37) +// CHECK:STDOUT: !33 = !DILocation(line: 49, column: 3, scope: !27) +// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.5bd8d5767580997a", scope: null, file: !1, line: 22, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !37) // CHECK:STDOUT: !35 = !DISubroutineType(types: !36) // CHECK:STDOUT: !36 = !{!30, !30, !30} // CHECK:STDOUT: !37 = !{!38, !39} // CHECK:STDOUT: !38 = !DILocalVariable(arg: 1, scope: !34, type: !30) // CHECK:STDOUT: !39 = !DILocalVariable(arg: 2, scope: !34, type: !30) -// CHECK:STDOUT: !40 = !DILocation(line: 22, column: 7, scope: !34) -// CHECK:STDOUT: !41 = !DILocation(line: 22, column: 6, scope: !34) -// CHECK:STDOUT: !42 = !DILocation(line: 23, column: 5, scope: !34) -// CHECK:STDOUT: !43 = !DILocation(line: 25, column: 7, scope: !34) -// CHECK:STDOUT: !44 = !DILocation(line: 25, column: 6, scope: !34) -// CHECK:STDOUT: !45 = !DILocation(line: 26, column: 12, scope: !34) -// CHECK:STDOUT: !46 = !DILocation(line: 26, column: 5, scope: !34) -// CHECK:STDOUT: !47 = !DILocation(line: 28, column: 12, scope: !34) -// CHECK:STDOUT: !48 = !DILocation(line: 28, column: 5, scope: !34) -// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.c27b765f2159c9a0", scope: null, file: !1, line: 21, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !52) +// CHECK:STDOUT: !40 = !DILocation(line: 23, column: 7, scope: !34) +// CHECK:STDOUT: !41 = !DILocation(line: 23, column: 6, scope: !34) +// CHECK:STDOUT: !42 = !DILocation(line: 24, column: 5, scope: !34) +// CHECK:STDOUT: !43 = !DILocation(line: 26, column: 7, scope: !34) +// CHECK:STDOUT: !44 = !DILocation(line: 26, column: 6, scope: !34) +// CHECK:STDOUT: !45 = !DILocation(line: 27, column: 12, scope: !34) +// CHECK:STDOUT: !46 = !DILocation(line: 27, column: 5, scope: !34) +// CHECK:STDOUT: !47 = !DILocation(line: 29, column: 12, scope: !34) +// CHECK:STDOUT: !48 = !DILocation(line: 29, column: 5, scope: !34) +// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.c27b765f2159c9a0", scope: null, file: !1, line: 22, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !52) // CHECK:STDOUT: !50 = !DISubroutineType(types: !51) // CHECK:STDOUT: !51 = !{!23, !23, !30} // CHECK:STDOUT: !52 = !{!53, !54} // CHECK:STDOUT: !53 = !DILocalVariable(arg: 1, scope: !49, type: !23) // CHECK:STDOUT: !54 = !DILocalVariable(arg: 2, scope: !49, type: !30) -// CHECK:STDOUT: !55 = !DILocation(line: 22, column: 7, scope: !49) -// CHECK:STDOUT: !56 = !DILocation(line: 22, column: 6, scope: !49) -// CHECK:STDOUT: !57 = !DILocation(line: 23, column: 5, scope: !49) -// CHECK:STDOUT: !58 = !DILocation(line: 25, column: 7, scope: !49) -// CHECK:STDOUT: !59 = !DILocation(line: 25, column: 6, scope: !49) -// CHECK:STDOUT: !60 = !DILocation(line: 26, column: 12, scope: !49) -// CHECK:STDOUT: !61 = !DILocation(line: 26, column: 5, scope: !49) -// CHECK:STDOUT: !62 = !DILocation(line: 28, column: 12, scope: !49) -// CHECK:STDOUT: !63 = !DILocation(line: 28, column: 5, scope: !49) -// CHECK:STDOUT: !64 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.2621742a01881e29", scope: null, file: !1, line: 21, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !65) +// CHECK:STDOUT: !55 = !DILocation(line: 23, column: 7, scope: !49) +// CHECK:STDOUT: !56 = !DILocation(line: 23, column: 6, scope: !49) +// CHECK:STDOUT: !57 = !DILocation(line: 24, column: 5, scope: !49) +// CHECK:STDOUT: !58 = !DILocation(line: 26, column: 7, scope: !49) +// CHECK:STDOUT: !59 = !DILocation(line: 26, column: 6, scope: !49) +// CHECK:STDOUT: !60 = !DILocation(line: 27, column: 12, scope: !49) +// CHECK:STDOUT: !61 = !DILocation(line: 27, column: 5, scope: !49) +// CHECK:STDOUT: !62 = !DILocation(line: 29, column: 12, scope: !49) +// CHECK:STDOUT: !63 = !DILocation(line: 29, column: 5, scope: !49) +// CHECK:STDOUT: !64 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.2621742a01881e29", scope: null, file: !1, line: 22, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !65) // CHECK:STDOUT: !65 = !{!66, !67} // CHECK:STDOUT: !66 = !DILocalVariable(arg: 1, scope: !64, type: !23) // CHECK:STDOUT: !67 = !DILocalVariable(arg: 2, scope: !64, type: !30) -// CHECK:STDOUT: !68 = !DILocation(line: 22, column: 7, scope: !64) -// CHECK:STDOUT: !69 = !DILocation(line: 22, column: 6, scope: !64) -// CHECK:STDOUT: !70 = !DILocation(line: 23, column: 5, scope: !64) -// CHECK:STDOUT: !71 = !DILocation(line: 25, column: 7, scope: !64) -// CHECK:STDOUT: !72 = !DILocation(line: 25, column: 6, scope: !64) -// CHECK:STDOUT: !73 = !DILocation(line: 26, column: 12, scope: !64) -// CHECK:STDOUT: !74 = !DILocation(line: 26, column: 5, scope: !64) -// CHECK:STDOUT: !75 = !DILocation(line: 28, column: 12, scope: !64) -// CHECK:STDOUT: !76 = !DILocation(line: 28, column: 5, scope: !64) -// CHECK:STDOUT: !77 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.5bd8d5767580997a", scope: null, file: !1, line: 33, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !78) +// CHECK:STDOUT: !68 = !DILocation(line: 23, column: 7, scope: !64) +// CHECK:STDOUT: !69 = !DILocation(line: 23, column: 6, scope: !64) +// CHECK:STDOUT: !70 = !DILocation(line: 24, column: 5, scope: !64) +// CHECK:STDOUT: !71 = !DILocation(line: 26, column: 7, scope: !64) +// CHECK:STDOUT: !72 = !DILocation(line: 26, column: 6, scope: !64) +// CHECK:STDOUT: !73 = !DILocation(line: 27, column: 12, scope: !64) +// CHECK:STDOUT: !74 = !DILocation(line: 27, column: 5, scope: !64) +// CHECK:STDOUT: !75 = !DILocation(line: 29, column: 12, scope: !64) +// CHECK:STDOUT: !76 = !DILocation(line: 29, column: 5, scope: !64) +// CHECK:STDOUT: !77 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.5bd8d5767580997a", scope: null, file: !1, line: 34, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !78) // CHECK:STDOUT: !78 = !{!79, !80} // CHECK:STDOUT: !79 = !DILocalVariable(arg: 1, scope: !77, type: !30) // CHECK:STDOUT: !80 = !DILocalVariable(arg: 2, scope: !77, type: !30) -// CHECK:STDOUT: !81 = !DILocation(line: 34, column: 3, scope: !77) -// CHECK:STDOUT: !82 = !DILocation(line: 35, column: 10, scope: !77) -// CHECK:STDOUT: !83 = !DILocation(line: 35, column: 3, scope: !77) -// CHECK:STDOUT: !84 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.5bd8d5767580997a", scope: null, file: !1, line: 38, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !85) +// CHECK:STDOUT: !81 = !DILocation(line: 35, column: 3, scope: !77) +// CHECK:STDOUT: !82 = !DILocation(line: 36, column: 10, scope: !77) +// CHECK:STDOUT: !83 = !DILocation(line: 36, column: 3, scope: !77) +// CHECK:STDOUT: !84 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.5bd8d5767580997a", scope: null, file: !1, line: 39, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !85) // CHECK:STDOUT: !85 = !{!86, !87} // CHECK:STDOUT: !86 = !DILocalVariable(arg: 1, scope: !84, type: !30) // CHECK:STDOUT: !87 = !DILocalVariable(arg: 2, scope: !84, type: !30) -// CHECK:STDOUT: !88 = !DILocation(line: 39, column: 3, scope: !84) -// CHECK:STDOUT: !89 = !DILocation(line: 40, column: 10, scope: !84) -// CHECK:STDOUT: !90 = !DILocation(line: 40, column: 3, scope: !84) -// CHECK:STDOUT: !91 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.c27b765f2159c9a0", scope: null, file: !1, line: 33, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !92) +// CHECK:STDOUT: !88 = !DILocation(line: 40, column: 3, scope: !84) +// CHECK:STDOUT: !89 = !DILocation(line: 41, column: 10, scope: !84) +// CHECK:STDOUT: !90 = !DILocation(line: 41, column: 3, scope: !84) +// CHECK:STDOUT: !91 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.c27b765f2159c9a0", scope: null, file: !1, line: 34, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !92) // CHECK:STDOUT: !92 = !{!93, !94} // CHECK:STDOUT: !93 = !DILocalVariable(arg: 1, scope: !91, type: !23) // CHECK:STDOUT: !94 = !DILocalVariable(arg: 2, scope: !91, type: !30) -// CHECK:STDOUT: !95 = !DILocation(line: 34, column: 3, scope: !91) -// CHECK:STDOUT: !96 = !DILocation(line: 35, column: 10, scope: !91) -// CHECK:STDOUT: !97 = !DILocation(line: 35, column: 3, scope: !91) -// CHECK:STDOUT: !98 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.c27b765f2159c9a0", scope: null, file: !1, line: 38, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !99) +// CHECK:STDOUT: !95 = !DILocation(line: 35, column: 3, scope: !91) +// CHECK:STDOUT: !96 = !DILocation(line: 36, column: 10, scope: !91) +// CHECK:STDOUT: !97 = !DILocation(line: 36, column: 3, scope: !91) +// CHECK:STDOUT: !98 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.c27b765f2159c9a0", scope: null, file: !1, line: 39, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !99) // CHECK:STDOUT: !99 = !{!100, !101} // CHECK:STDOUT: !100 = !DILocalVariable(arg: 1, scope: !98, type: !23) // CHECK:STDOUT: !101 = !DILocalVariable(arg: 2, scope: !98, type: !30) -// CHECK:STDOUT: !102 = !DILocation(line: 39, column: 3, scope: !98) -// CHECK:STDOUT: !103 = !DILocation(line: 40, column: 10, scope: !98) -// CHECK:STDOUT: !104 = !DILocation(line: 40, column: 3, scope: !98) -// CHECK:STDOUT: !105 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.2621742a01881e29", scope: null, file: !1, line: 33, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !106) +// CHECK:STDOUT: !102 = !DILocation(line: 40, column: 3, scope: !98) +// CHECK:STDOUT: !103 = !DILocation(line: 41, column: 10, scope: !98) +// CHECK:STDOUT: !104 = !DILocation(line: 41, column: 3, scope: !98) +// CHECK:STDOUT: !105 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.2621742a01881e29", scope: null, file: !1, line: 34, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !106) // CHECK:STDOUT: !106 = !{!107, !108} // CHECK:STDOUT: !107 = !DILocalVariable(arg: 1, scope: !105, type: !23) // CHECK:STDOUT: !108 = !DILocalVariable(arg: 2, scope: !105, type: !30) -// CHECK:STDOUT: !109 = !DILocation(line: 34, column: 3, scope: !105) -// CHECK:STDOUT: !110 = !DILocation(line: 35, column: 10, scope: !105) -// CHECK:STDOUT: !111 = !DILocation(line: 35, column: 3, scope: !105) -// CHECK:STDOUT: !112 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.2621742a01881e29", scope: null, file: !1, line: 38, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !113) +// CHECK:STDOUT: !109 = !DILocation(line: 35, column: 3, scope: !105) +// CHECK:STDOUT: !110 = !DILocation(line: 36, column: 10, scope: !105) +// CHECK:STDOUT: !111 = !DILocation(line: 36, column: 3, scope: !105) +// CHECK:STDOUT: !112 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.2621742a01881e29", scope: null, file: !1, line: 39, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !113) // CHECK:STDOUT: !113 = !{!114, !115} // CHECK:STDOUT: !114 = !DILocalVariable(arg: 1, scope: !112, type: !23) // CHECK:STDOUT: !115 = !DILocalVariable(arg: 2, scope: !112, type: !30) -// CHECK:STDOUT: !116 = !DILocation(line: 39, column: 3, scope: !112) -// CHECK:STDOUT: !117 = !DILocation(line: 40, column: 10, scope: !112) -// CHECK:STDOUT: !118 = !DILocation(line: 40, column: 3, scope: !112) -// CHECK:STDOUT: !119 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.5bd8d5767580997a", scope: null, file: !1, line: 43, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !120) +// CHECK:STDOUT: !116 = !DILocation(line: 40, column: 3, scope: !112) +// CHECK:STDOUT: !117 = !DILocation(line: 41, column: 10, scope: !112) +// CHECK:STDOUT: !118 = !DILocation(line: 41, column: 3, scope: !112) +// CHECK:STDOUT: !119 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.5bd8d5767580997a", scope: null, file: !1, line: 44, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !120) // CHECK:STDOUT: !120 = !{!121, !122} // CHECK:STDOUT: !121 = !DILocalVariable(arg: 1, scope: !119, type: !30) // CHECK:STDOUT: !122 = !DILocalVariable(arg: 2, scope: !119, type: !30) -// CHECK:STDOUT: !123 = !DILocation(line: 44, column: 15, scope: !119) -// CHECK:STDOUT: !124 = !DILocation(line: 44, column: 10, scope: !119) -// CHECK:STDOUT: !125 = !DILocation(line: 44, column: 3, scope: !119) -// CHECK:STDOUT: !126 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.c27b765f2159c9a0", scope: null, file: !1, line: 43, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !127) +// CHECK:STDOUT: !123 = !DILocation(line: 45, column: 15, scope: !119) +// CHECK:STDOUT: !124 = !DILocation(line: 45, column: 10, scope: !119) +// CHECK:STDOUT: !125 = !DILocation(line: 45, column: 3, scope: !119) +// CHECK:STDOUT: !126 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.c27b765f2159c9a0", scope: null, file: !1, line: 44, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !127) // CHECK:STDOUT: !127 = !{!128, !129} // CHECK:STDOUT: !128 = !DILocalVariable(arg: 1, scope: !126, type: !23) // CHECK:STDOUT: !129 = !DILocalVariable(arg: 2, scope: !126, type: !30) -// CHECK:STDOUT: !130 = !DILocation(line: 44, column: 15, scope: !126) -// CHECK:STDOUT: !131 = !DILocation(line: 44, column: 10, scope: !126) -// CHECK:STDOUT: !132 = !DILocation(line: 44, column: 3, scope: !126) -// CHECK:STDOUT: !133 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.2621742a01881e29", scope: null, file: !1, line: 43, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !134) +// CHECK:STDOUT: !130 = !DILocation(line: 45, column: 15, scope: !126) +// CHECK:STDOUT: !131 = !DILocation(line: 45, column: 10, scope: !126) +// CHECK:STDOUT: !132 = !DILocation(line: 45, column: 3, scope: !126) +// CHECK:STDOUT: !133 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.2621742a01881e29", scope: null, file: !1, line: 44, type: !50, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !134) // CHECK:STDOUT: !134 = !{!135, !136} // CHECK:STDOUT: !135 = !DILocalVariable(arg: 1, scope: !133, type: !23) // CHECK:STDOUT: !136 = !DILocalVariable(arg: 2, scope: !133, type: !30) -// CHECK:STDOUT: !137 = !DILocation(line: 44, column: 15, scope: !133) -// CHECK:STDOUT: !138 = !DILocation(line: 44, column: 10, scope: !133) -// CHECK:STDOUT: !139 = !DILocation(line: 44, column: 3, scope: !133) +// CHECK:STDOUT: !137 = !DILocation(line: 45, column: 15, scope: !133) +// CHECK:STDOUT: !138 = !DILocation(line: 45, column: 10, scope: !133) +// CHECK:STDOUT: !139 = !DILocation(line: 45, column: 3, scope: !133) // CHECK:STDOUT: diff --git a/toolchain/lower/testdata/function/generic/call_recursive_impl.carbon b/toolchain/lower/testdata/function/generic/call_recursive_impl.carbon index d3d781e9af7e..02de8402ef00 100644 --- a/toolchain/lower/testdata/function/generic/call_recursive_impl.carbon +++ b/toolchain/lower/testdata/function/generic/call_recursive_impl.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -64,8 +65,8 @@ fn Run() { // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define i32 @main() #0 !dbg !12 { // CHECK:STDOUT: entry: -// CHECK:STDOUT: %G.call.loc40 = call i32 @_CG.Main.c81631f865470482(i32 0), !dbg !16 -// CHECK:STDOUT: %G.call.loc41 = call i32 @_CG.Main.0b241ec84a68877b(i32 0), !dbg !17 +// CHECK:STDOUT: %G.call.loc41 = call i32 @_CG.Main.c81631f865470482(i32 0), !dbg !16 +// CHECK:STDOUT: %G.call.loc42 = call i32 @_CG.Main.0b241ec84a68877b(i32 0), !dbg !17 // CHECK:STDOUT: ret i32 0, !dbg !18 // CHECK:STDOUT: } // CHECK:STDOUT: @@ -115,41 +116,41 @@ fn Run() { // CHECK:STDOUT: !1 = !DIFile(filename: "call_recursive_impl.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.X.Main:I.Main", scope: null, file: !1, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.X.Main:I.Main", scope: null, file: !1, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{null} -// CHECK:STDOUT: !7 = !DILocation(line: 20, column: 12, scope: !4) -// CHECK:STDOUT: !8 = !DILocation(line: 20, column: 3, scope: !4) -// CHECK:STDOUT: !9 = distinct !DISubprogram(name: "F", linkageName: "_CF.Y.Main:I.Main", scope: null, file: !1, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !0) -// CHECK:STDOUT: !10 = !DILocation(line: 24, column: 12, scope: !9) -// CHECK:STDOUT: !11 = !DILocation(line: 24, column: 3, scope: !9) -// CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !1, line: 39, type: !13, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !7 = !DILocation(line: 21, column: 12, scope: !4) +// CHECK:STDOUT: !8 = !DILocation(line: 21, column: 3, scope: !4) +// CHECK:STDOUT: !9 = distinct !DISubprogram(name: "F", linkageName: "_CF.Y.Main:I.Main", scope: null, file: !1, line: 25, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !10 = !DILocation(line: 25, column: 12, scope: !9) +// CHECK:STDOUT: !11 = !DILocation(line: 25, column: 3, scope: !9) +// CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !1, line: 40, type: !13, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !13 = !DISubroutineType(types: !14) // CHECK:STDOUT: !14 = !{!15} // CHECK:STDOUT: !15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -// CHECK:STDOUT: !16 = !DILocation(line: 40, column: 3, scope: !12) -// CHECK:STDOUT: !17 = !DILocation(line: 41, column: 3, scope: !12) -// CHECK:STDOUT: !18 = !DILocation(line: 39, column: 1, scope: !12) -// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c81631f865470482", scope: null, file: !1, line: 30, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !22) +// CHECK:STDOUT: !16 = !DILocation(line: 41, column: 3, scope: !12) +// CHECK:STDOUT: !17 = !DILocation(line: 42, column: 3, scope: !12) +// CHECK:STDOUT: !18 = !DILocation(line: 40, column: 1, scope: !12) +// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c81631f865470482", scope: null, file: !1, line: 31, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !22) // CHECK:STDOUT: !20 = !DISubroutineType(types: !21) // CHECK:STDOUT: !21 = !{!15, !15} // CHECK:STDOUT: !22 = !{!23} // CHECK:STDOUT: !23 = !DILocalVariable(arg: 1, scope: !19, type: !15) -// CHECK:STDOUT: !24 = !DILocation(line: 31, column: 3, scope: !19) -// CHECK:STDOUT: !25 = !DILocation(line: 33, column: 7, scope: !19) -// CHECK:STDOUT: !26 = !DILocation(line: 33, column: 6, scope: !19) -// CHECK:STDOUT: !27 = !DILocation(line: 34, column: 5, scope: !19) -// CHECK:STDOUT: !28 = !DILocation(line: 36, column: 15, scope: !19) -// CHECK:STDOUT: !29 = !DILocation(line: 36, column: 10, scope: !19) -// CHECK:STDOUT: !30 = !DILocation(line: 36, column: 3, scope: !19) -// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.0b241ec84a68877b", scope: null, file: !1, line: 30, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !32) +// CHECK:STDOUT: !24 = !DILocation(line: 32, column: 3, scope: !19) +// CHECK:STDOUT: !25 = !DILocation(line: 34, column: 7, scope: !19) +// CHECK:STDOUT: !26 = !DILocation(line: 34, column: 6, scope: !19) +// CHECK:STDOUT: !27 = !DILocation(line: 35, column: 5, scope: !19) +// CHECK:STDOUT: !28 = !DILocation(line: 37, column: 15, scope: !19) +// CHECK:STDOUT: !29 = !DILocation(line: 37, column: 10, scope: !19) +// CHECK:STDOUT: !30 = !DILocation(line: 37, column: 3, scope: !19) +// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.0b241ec84a68877b", scope: null, file: !1, line: 31, type: !20, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !32) // CHECK:STDOUT: !32 = !{!33} // CHECK:STDOUT: !33 = !DILocalVariable(arg: 1, scope: !31, type: !15) -// CHECK:STDOUT: !34 = !DILocation(line: 31, column: 3, scope: !31) -// CHECK:STDOUT: !35 = !DILocation(line: 33, column: 7, scope: !31) -// CHECK:STDOUT: !36 = !DILocation(line: 33, column: 6, scope: !31) -// CHECK:STDOUT: !37 = !DILocation(line: 34, column: 5, scope: !31) -// CHECK:STDOUT: !38 = !DILocation(line: 36, column: 15, scope: !31) -// CHECK:STDOUT: !39 = !DILocation(line: 36, column: 10, scope: !31) -// CHECK:STDOUT: !40 = !DILocation(line: 36, column: 3, scope: !31) +// CHECK:STDOUT: !34 = !DILocation(line: 32, column: 3, scope: !31) +// CHECK:STDOUT: !35 = !DILocation(line: 34, column: 7, scope: !31) +// CHECK:STDOUT: !36 = !DILocation(line: 34, column: 6, scope: !31) +// CHECK:STDOUT: !37 = !DILocation(line: 35, column: 5, scope: !31) +// CHECK:STDOUT: !38 = !DILocation(line: 37, column: 15, scope: !31) +// CHECK:STDOUT: !39 = !DILocation(line: 37, column: 10, scope: !31) +// CHECK:STDOUT: !40 = !DILocation(line: 37, column: 3, scope: !31) // CHECK:STDOUT: diff --git a/toolchain/lower/testdata/function/generic/call_recursive_sccs_deep.carbon b/toolchain/lower/testdata/function/generic/call_recursive_sccs_deep.carbon index 2996caa05eb9..1466f33635a0 100644 --- a/toolchain/lower/testdata/function/generic/call_recursive_sccs_deep.carbon +++ b/toolchain/lower/testdata/function/generic/call_recursive_sccs_deep.carbon @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // +// EXTRA-ARGS: --include-carbon-core // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon // // AUTOUPDATE @@ -103,14 +104,14 @@ fn M() { // CHECK:STDOUT: store ptr %n.var, ptr %ptr_i32.var, align 8, !dbg !9 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_f64.var), !dbg !10 // CHECK:STDOUT: store ptr %m.var, ptr %ptr_f64.var, align 8, !dbg !10 -// CHECK:STDOUT: %.loc79_5 = load i32, ptr %n.var, align 4, !dbg !11 -// CHECK:STDOUT: %A.call.loc79 = call i32 @_CA.Main.5bd8d5767580997a(i32 %.loc79_5, i32 0), !dbg !12 -// CHECK:STDOUT: %.loc80_5 = load double, ptr %m.var, align 8, !dbg !13 -// CHECK:STDOUT: %A.call.loc80 = call double @_CA.Main.c27b765f2159c9a0(double %.loc80_5, i32 0), !dbg !14 -// CHECK:STDOUT: %.loc81_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15 -// CHECK:STDOUT: %A.call.loc81 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc81_5, i32 0), !dbg !16 -// CHECK:STDOUT: %.loc82_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17 -// CHECK:STDOUT: %A.call.loc82 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc82_5, i32 0), !dbg !18 +// CHECK:STDOUT: %.loc80_5 = load i32, ptr %n.var, align 4, !dbg !11 +// CHECK:STDOUT: %A.call.loc80 = call i32 @_CA.Main.5bd8d5767580997a(i32 %.loc80_5, i32 0), !dbg !12 +// CHECK:STDOUT: %.loc81_5 = load double, ptr %m.var, align 8, !dbg !13 +// CHECK:STDOUT: %A.call.loc81 = call double @_CA.Main.c27b765f2159c9a0(double %.loc81_5, i32 0), !dbg !14 +// CHECK:STDOUT: %.loc82_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15 +// CHECK:STDOUT: %A.call.loc82 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc82_5, i32 0), !dbg !16 +// CHECK:STDOUT: %.loc83_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17 +// CHECK:STDOUT: %A.call.loc83 = call ptr @_CA.Main.2621742a01881e29(ptr %.loc83_5, i32 0), !dbg !18 // CHECK:STDOUT: call void @"_COp.30d8007fdcc57f83:core.Destroy.Core"(ptr %m.var), !dbg !8 // CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %n.var), !dbg !7 // CHECK:STDOUT: ret void, !dbg !19 @@ -166,21 +167,21 @@ fn M() { // CHECK:STDOUT: define linkonce_odr i32 @_CD.Main.5bd8d5767580997a(i32 %x, i32 %count) #0 !dbg !67 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %Int.as.OrderedWith.impl.Greater.call = icmp sgt i32 %count, 4, !dbg !71 -// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc48, label %if.else.loc48, !dbg !72 +// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc49, label %if.else.loc49, !dbg !72 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc48: ; preds = %entry +// CHECK:STDOUT: if.then.loc49: ; preds = %entry // CHECK:STDOUT: ret i32 %x, !dbg !73 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc48: ; preds = %entry +// CHECK:STDOUT: if.else.loc49: ; preds = %entry // CHECK:STDOUT: %Int.as.ModWith.impl.Op.call = srem i32 %count, 2, !dbg !74 // CHECK:STDOUT: %Int.as.EqWith.impl.Equal.call = icmp eq i32 %Int.as.ModWith.impl.Op.call, 0, !dbg !74 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc51, label %if.else.loc51, !dbg !75 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc52, label %if.else.loc52, !dbg !75 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc51: ; preds = %if.else.loc48 +// CHECK:STDOUT: if.then.loc52: ; preds = %if.else.loc49 // CHECK:STDOUT: %E.call = call i32 @_CE.Main.5bd8d5767580997a(i32 %x, i32 %count), !dbg !76 // CHECK:STDOUT: ret i32 %E.call, !dbg !77 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc51: ; preds = %if.else.loc48 +// CHECK:STDOUT: if.else.loc52: ; preds = %if.else.loc49 // CHECK:STDOUT: %F.call = call i32 @_CF.Main.5bd8d5767580997a(i32 %x, i32 %count), !dbg !78 // CHECK:STDOUT: ret i32 %F.call, !dbg !79 // CHECK:STDOUT: } @@ -196,21 +197,21 @@ fn M() { // CHECK:STDOUT: define linkonce_odr double @_CD.Main.c27b765f2159c9a0(double %x, i32 %count) #0 !dbg !88 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %Int.as.OrderedWith.impl.Greater.call = icmp sgt i32 %count, 4, !dbg !92 -// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc48, label %if.else.loc48, !dbg !93 +// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc49, label %if.else.loc49, !dbg !93 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc48: ; preds = %entry +// CHECK:STDOUT: if.then.loc49: ; preds = %entry // CHECK:STDOUT: ret double %x, !dbg !94 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc48: ; preds = %entry +// CHECK:STDOUT: if.else.loc49: ; preds = %entry // CHECK:STDOUT: %Int.as.ModWith.impl.Op.call = srem i32 %count, 2, !dbg !95 // CHECK:STDOUT: %Int.as.EqWith.impl.Equal.call = icmp eq i32 %Int.as.ModWith.impl.Op.call, 0, !dbg !95 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc51, label %if.else.loc51, !dbg !96 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc52, label %if.else.loc52, !dbg !96 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc51: ; preds = %if.else.loc48 +// CHECK:STDOUT: if.then.loc52: ; preds = %if.else.loc49 // CHECK:STDOUT: %E.call = call double @_CE.Main.c27b765f2159c9a0(double %x, i32 %count), !dbg !97 // CHECK:STDOUT: ret double %E.call, !dbg !98 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc51: ; preds = %if.else.loc48 +// CHECK:STDOUT: if.else.loc52: ; preds = %if.else.loc49 // CHECK:STDOUT: %F.call = call double @_CF.Main.c27b765f2159c9a0(double %x, i32 %count), !dbg !99 // CHECK:STDOUT: ret double %F.call, !dbg !100 // CHECK:STDOUT: } @@ -226,21 +227,21 @@ fn M() { // CHECK:STDOUT: define linkonce_odr ptr @_CD.Main.2621742a01881e29(ptr %x, i32 %count) #0 !dbg !107 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %Int.as.OrderedWith.impl.Greater.call = icmp sgt i32 %count, 4, !dbg !111 -// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc48, label %if.else.loc48, !dbg !112 +// CHECK:STDOUT: br i1 %Int.as.OrderedWith.impl.Greater.call, label %if.then.loc49, label %if.else.loc49, !dbg !112 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc48: ; preds = %entry +// CHECK:STDOUT: if.then.loc49: ; preds = %entry // CHECK:STDOUT: ret ptr %x, !dbg !113 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc48: ; preds = %entry +// CHECK:STDOUT: if.else.loc49: ; preds = %entry // CHECK:STDOUT: %Int.as.ModWith.impl.Op.call = srem i32 %count, 2, !dbg !114 // CHECK:STDOUT: %Int.as.EqWith.impl.Equal.call = icmp eq i32 %Int.as.ModWith.impl.Op.call, 0, !dbg !114 -// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc51, label %if.else.loc51, !dbg !115 +// CHECK:STDOUT: br i1 %Int.as.EqWith.impl.Equal.call, label %if.then.loc52, label %if.else.loc52, !dbg !115 // CHECK:STDOUT: -// CHECK:STDOUT: if.then.loc51: ; preds = %if.else.loc48 +// CHECK:STDOUT: if.then.loc52: ; preds = %if.else.loc49 // CHECK:STDOUT: %E.call = call ptr @_CE.Main.2621742a01881e29(ptr %x, i32 %count), !dbg !116 // CHECK:STDOUT: ret ptr %E.call, !dbg !117 // CHECK:STDOUT: -// CHECK:STDOUT: if.else.loc51: ; preds = %if.else.loc48 +// CHECK:STDOUT: if.else.loc52: ; preds = %if.else.loc49 // CHECK:STDOUT: %F.call = call ptr @_CF.Main.2621742a01881e29(ptr %x, i32 %count), !dbg !118 // CHECK:STDOUT: ret ptr %F.call, !dbg !119 // CHECK:STDOUT: } @@ -379,210 +380,210 @@ fn M() { // CHECK:STDOUT: !1 = !DIFile(filename: "call_recursive_sccs_deep.carbon", directory: "") // CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5} // CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3} -// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !1, line: 73, type: !5, spFlags: DISPFlagDefinition, unit: !0) +// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !1, line: 74, type: !5, spFlags: DISPFlagDefinition, unit: !0) // CHECK:STDOUT: !5 = !DISubroutineType(types: !6) // CHECK:STDOUT: !6 = !{null} -// CHECK:STDOUT: !7 = !DILocation(line: 74, column: 3, scope: !4) -// CHECK:STDOUT: !8 = !DILocation(line: 75, column: 3, scope: !4) -// CHECK:STDOUT: !9 = !DILocation(line: 76, column: 3, scope: !4) -// CHECK:STDOUT: !10 = !DILocation(line: 77, column: 3, scope: !4) -// CHECK:STDOUT: !11 = !DILocation(line: 79, column: 5, scope: !4) -// CHECK:STDOUT: !12 = !DILocation(line: 79, column: 3, scope: !4) -// CHECK:STDOUT: !13 = !DILocation(line: 80, column: 5, scope: !4) -// CHECK:STDOUT: !14 = !DILocation(line: 80, column: 3, scope: !4) -// CHECK:STDOUT: !15 = !DILocation(line: 81, column: 5, scope: !4) -// CHECK:STDOUT: !16 = !DILocation(line: 81, column: 3, scope: !4) -// CHECK:STDOUT: !17 = !DILocation(line: 82, column: 5, scope: !4) -// CHECK:STDOUT: !18 = !DILocation(line: 82, column: 3, scope: !4) -// CHECK:STDOUT: !19 = !DILocation(line: 73, column: 1, scope: !4) -// CHECK:STDOUT: !20 = distinct !DISubprogram(name: "Op", linkageName: "_COp.30d8007fdcc57f83:core.Destroy.Core", scope: null, file: !1, line: 75, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !24) +// CHECK:STDOUT: !7 = !DILocation(line: 75, column: 3, scope: !4) +// CHECK:STDOUT: !8 = !DILocation(line: 76, column: 3, scope: !4) +// CHECK:STDOUT: !9 = !DILocation(line: 77, column: 3, scope: !4) +// CHECK:STDOUT: !10 = !DILocation(line: 78, column: 3, scope: !4) +// CHECK:STDOUT: !11 = !DILocation(line: 80, column: 5, scope: !4) +// CHECK:STDOUT: !12 = !DILocation(line: 80, column: 3, scope: !4) +// CHECK:STDOUT: !13 = !DILocation(line: 81, column: 5, scope: !4) +// CHECK:STDOUT: !14 = !DILocation(line: 81, column: 3, scope: !4) +// CHECK:STDOUT: !15 = !DILocation(line: 82, column: 5, scope: !4) +// CHECK:STDOUT: !16 = !DILocation(line: 82, column: 3, scope: !4) +// CHECK:STDOUT: !17 = !DILocation(line: 83, column: 5, scope: !4) +// CHECK:STDOUT: !18 = !DILocation(line: 83, column: 3, scope: !4) +// CHECK:STDOUT: !19 = !DILocation(line: 74, column: 1, scope: !4) +// CHECK:STDOUT: !20 = distinct !DISubprogram(name: "Op", linkageName: "_COp.30d8007fdcc57f83:core.Destroy.Core", scope: null, file: !1, line: 76, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !24) // CHECK:STDOUT: !21 = !DISubroutineType(types: !22) // CHECK:STDOUT: !22 = !{null, !23} // CHECK:STDOUT: !23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) // CHECK:STDOUT: !24 = !{!25} // CHECK:STDOUT: !25 = !DILocalVariable(arg: 1, scope: !20, type: !23) -// CHECK:STDOUT: !26 = !DILocation(line: 75, column: 3, scope: !20) -// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 74, type: !28, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !31) +// CHECK:STDOUT: !26 = !DILocation(line: 76, column: 3, scope: !20) +// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 75, type: !28, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !31) // CHECK:STDOUT: !28 = !DISubroutineType(types: !29) // CHECK:STDOUT: !29 = !{null, !30} // CHECK:STDOUT: !30 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) // CHECK:STDOUT: !31 = !{!32} // CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !27, type: !30) -// CHECK:STDOUT: !33 = !DILocation(line: 74, column: 3, scope: !27) -// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.5bd8d5767580997a", scope: null, file: !1, line: 31, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !37) +// CHECK:STDOUT: !33 = !DILocation(line: 75, column: 3, scope: !27) +// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.5bd8d5767580997a", scope: null, file: !1, line: 32, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !37) // CHECK:STDOUT: !35 = !DISubroutineType(types: !36) // CHECK:STDOUT: !36 = !{!30, !30, !30} // CHECK:STDOUT: !37 = !{!38, !39} // CHECK:STDOUT: !38 = !DILocalVariable(arg: 1, scope: !34, type: !30) // CHECK:STDOUT: !39 = !DILocalVariable(arg: 2, scope: !34, type: !30) -// CHECK:STDOUT: !40 = !DILocation(line: 32, column: 3, scope: !34) -// CHECK:STDOUT: !41 = !DILocation(line: 33, column: 10, scope: !34) -// CHECK:STDOUT: !42 = !DILocation(line: 33, column: 3, scope: !34) -// CHECK:STDOUT: !43 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.c27b765f2159c9a0", scope: null, file: !1, line: 31, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !46) +// CHECK:STDOUT: !40 = !DILocation(line: 33, column: 3, scope: !34) +// CHECK:STDOUT: !41 = !DILocation(line: 34, column: 10, scope: !34) +// CHECK:STDOUT: !42 = !DILocation(line: 34, column: 3, scope: !34) +// CHECK:STDOUT: !43 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.c27b765f2159c9a0", scope: null, file: !1, line: 32, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !46) // CHECK:STDOUT: !44 = !DISubroutineType(types: !45) // CHECK:STDOUT: !45 = !{!23, !23, !30} // CHECK:STDOUT: !46 = !{!47, !48} // CHECK:STDOUT: !47 = !DILocalVariable(arg: 1, scope: !43, type: !23) // CHECK:STDOUT: !48 = !DILocalVariable(arg: 2, scope: !43, type: !30) -// CHECK:STDOUT: !49 = !DILocation(line: 32, column: 3, scope: !43) -// CHECK:STDOUT: !50 = !DILocation(line: 33, column: 10, scope: !43) -// CHECK:STDOUT: !51 = !DILocation(line: 33, column: 3, scope: !43) -// CHECK:STDOUT: !52 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.2621742a01881e29", scope: null, file: !1, line: 31, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !53) +// CHECK:STDOUT: !49 = !DILocation(line: 33, column: 3, scope: !43) +// CHECK:STDOUT: !50 = !DILocation(line: 34, column: 10, scope: !43) +// CHECK:STDOUT: !51 = !DILocation(line: 34, column: 3, scope: !43) +// CHECK:STDOUT: !52 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.2621742a01881e29", scope: null, file: !1, line: 32, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !53) // CHECK:STDOUT: !53 = !{!54, !55} // CHECK:STDOUT: !54 = !DILocalVariable(arg: 1, scope: !52, type: !23) // CHECK:STDOUT: !55 = !DILocalVariable(arg: 2, scope: !52, type: !30) -// CHECK:STDOUT: !56 = !DILocation(line: 32, column: 3, scope: !52) -// CHECK:STDOUT: !57 = !DILocation(line: 33, column: 10, scope: !52) -// CHECK:STDOUT: !58 = !DILocation(line: 33, column: 3, scope: !52) -// CHECK:STDOUT: !59 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.5bd8d5767580997a", scope: null, file: !1, line: 36, type: !60, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !62) +// CHECK:STDOUT: !56 = !DILocation(line: 33, column: 3, scope: !52) +// CHECK:STDOUT: !57 = !DILocation(line: 34, column: 10, scope: !52) +// CHECK:STDOUT: !58 = !DILocation(line: 34, column: 3, scope: !52) +// CHECK:STDOUT: !59 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.5bd8d5767580997a", scope: null, file: !1, line: 37, type: !60, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !62) // CHECK:STDOUT: !60 = !DISubroutineType(types: !61) // CHECK:STDOUT: !61 = !{null, !30, !30} // CHECK:STDOUT: !62 = !{!63, !64} // CHECK:STDOUT: !63 = !DILocalVariable(arg: 1, scope: !59, type: !30) // CHECK:STDOUT: !64 = !DILocalVariable(arg: 2, scope: !59, type: !30) -// CHECK:STDOUT: !65 = !DILocation(line: 37, column: 3, scope: !59) -// CHECK:STDOUT: !66 = !DILocation(line: 36, column: 1, scope: !59) -// CHECK:STDOUT: !67 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.5bd8d5767580997a", scope: null, file: !1, line: 47, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !68) +// CHECK:STDOUT: !65 = !DILocation(line: 38, column: 3, scope: !59) +// CHECK:STDOUT: !66 = !DILocation(line: 37, column: 1, scope: !59) +// CHECK:STDOUT: !67 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.5bd8d5767580997a", scope: null, file: !1, line: 48, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !68) // CHECK:STDOUT: !68 = !{!69, !70} // CHECK:STDOUT: !69 = !DILocalVariable(arg: 1, scope: !67, type: !30) // CHECK:STDOUT: !70 = !DILocalVariable(arg: 2, scope: !67, type: !30) -// CHECK:STDOUT: !71 = !DILocation(line: 48, column: 7, scope: !67) -// CHECK:STDOUT: !72 = !DILocation(line: 48, column: 6, scope: !67) -// CHECK:STDOUT: !73 = !DILocation(line: 49, column: 5, scope: !67) -// CHECK:STDOUT: !74 = !DILocation(line: 51, column: 7, scope: !67) -// CHECK:STDOUT: !75 = !DILocation(line: 51, column: 6, scope: !67) -// CHECK:STDOUT: !76 = !DILocation(line: 52, column: 12, scope: !67) -// CHECK:STDOUT: !77 = !DILocation(line: 52, column: 5, scope: !67) -// CHECK:STDOUT: !78 = !DILocation(line: 54, column: 12, scope: !67) -// CHECK:STDOUT: !79 = !DILocation(line: 54, column: 5, scope: !67) -// CHECK:STDOUT: !80 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.c27b765f2159c9a0", scope: null, file: !1, line: 36, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !83) +// CHECK:STDOUT: !71 = !DILocation(line: 49, column: 7, scope: !67) +// CHECK:STDOUT: !72 = !DILocation(line: 49, column: 6, scope: !67) +// CHECK:STDOUT: !73 = !DILocation(line: 50, column: 5, scope: !67) +// CHECK:STDOUT: !74 = !DILocation(line: 52, column: 7, scope: !67) +// CHECK:STDOUT: !75 = !DILocation(line: 52, column: 6, scope: !67) +// CHECK:STDOUT: !76 = !DILocation(line: 53, column: 12, scope: !67) +// CHECK:STDOUT: !77 = !DILocation(line: 53, column: 5, scope: !67) +// CHECK:STDOUT: !78 = !DILocation(line: 55, column: 12, scope: !67) +// CHECK:STDOUT: !79 = !DILocation(line: 55, column: 5, scope: !67) +// CHECK:STDOUT: !80 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.c27b765f2159c9a0", scope: null, file: !1, line: 37, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !83) // CHECK:STDOUT: !81 = !DISubroutineType(types: !82) // CHECK:STDOUT: !82 = !{null, !23, !30} // CHECK:STDOUT: !83 = !{!84, !85} // CHECK:STDOUT: !84 = !DILocalVariable(arg: 1, scope: !80, type: !23) // CHECK:STDOUT: !85 = !DILocalVariable(arg: 2, scope: !80, type: !30) -// CHECK:STDOUT: !86 = !DILocation(line: 37, column: 3, scope: !80) -// CHECK:STDOUT: !87 = !DILocation(line: 36, column: 1, scope: !80) -// CHECK:STDOUT: !88 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.c27b765f2159c9a0", scope: null, file: !1, line: 47, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !89) +// CHECK:STDOUT: !86 = !DILocation(line: 38, column: 3, scope: !80) +// CHECK:STDOUT: !87 = !DILocation(line: 37, column: 1, scope: !80) +// CHECK:STDOUT: !88 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.c27b765f2159c9a0", scope: null, file: !1, line: 48, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !89) // CHECK:STDOUT: !89 = !{!90, !91} // CHECK:STDOUT: !90 = !DILocalVariable(arg: 1, scope: !88, type: !23) // CHECK:STDOUT: !91 = !DILocalVariable(arg: 2, scope: !88, type: !30) -// CHECK:STDOUT: !92 = !DILocation(line: 48, column: 7, scope: !88) -// CHECK:STDOUT: !93 = !DILocation(line: 48, column: 6, scope: !88) -// CHECK:STDOUT: !94 = !DILocation(line: 49, column: 5, scope: !88) -// CHECK:STDOUT: !95 = !DILocation(line: 51, column: 7, scope: !88) -// CHECK:STDOUT: !96 = !DILocation(line: 51, column: 6, scope: !88) -// CHECK:STDOUT: !97 = !DILocation(line: 52, column: 12, scope: !88) -// CHECK:STDOUT: !98 = !DILocation(line: 52, column: 5, scope: !88) -// CHECK:STDOUT: !99 = !DILocation(line: 54, column: 12, scope: !88) -// CHECK:STDOUT: !100 = !DILocation(line: 54, column: 5, scope: !88) -// CHECK:STDOUT: !101 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.2621742a01881e29", scope: null, file: !1, line: 36, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !102) +// CHECK:STDOUT: !92 = !DILocation(line: 49, column: 7, scope: !88) +// CHECK:STDOUT: !93 = !DILocation(line: 49, column: 6, scope: !88) +// CHECK:STDOUT: !94 = !DILocation(line: 50, column: 5, scope: !88) +// CHECK:STDOUT: !95 = !DILocation(line: 52, column: 7, scope: !88) +// CHECK:STDOUT: !96 = !DILocation(line: 52, column: 6, scope: !88) +// CHECK:STDOUT: !97 = !DILocation(line: 53, column: 12, scope: !88) +// CHECK:STDOUT: !98 = !DILocation(line: 53, column: 5, scope: !88) +// CHECK:STDOUT: !99 = !DILocation(line: 55, column: 12, scope: !88) +// CHECK:STDOUT: !100 = !DILocation(line: 55, column: 5, scope: !88) +// CHECK:STDOUT: !101 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.2621742a01881e29", scope: null, file: !1, line: 37, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !102) // CHECK:STDOUT: !102 = !{!103, !104} // CHECK:STDOUT: !103 = !DILocalVariable(arg: 1, scope: !101, type: !23) // CHECK:STDOUT: !104 = !DILocalVariable(arg: 2, scope: !101, type: !30) -// CHECK:STDOUT: !105 = !DILocation(line: 37, column: 3, scope: !101) -// CHECK:STDOUT: !106 = !DILocation(line: 36, column: 1, scope: !101) -// CHECK:STDOUT: !107 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.2621742a01881e29", scope: null, file: !1, line: 47, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !108) +// CHECK:STDOUT: !105 = !DILocation(line: 38, column: 3, scope: !101) +// CHECK:STDOUT: !106 = !DILocation(line: 37, column: 1, scope: !101) +// CHECK:STDOUT: !107 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.2621742a01881e29", scope: null, file: !1, line: 48, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !108) // CHECK:STDOUT: !108 = !{!109, !110} // CHECK:STDOUT: !109 = !DILocalVariable(arg: 1, scope: !107, type: !23) // CHECK:STDOUT: !110 = !DILocalVariable(arg: 2, scope: !107, type: !30) -// CHECK:STDOUT: !111 = !DILocation(line: 48, column: 7, scope: !107) -// CHECK:STDOUT: !112 = !DILocation(line: 48, column: 6, scope: !107) -// CHECK:STDOUT: !113 = !DILocation(line: 49, column: 5, scope: !107) -// CHECK:STDOUT: !114 = !DILocation(line: 51, column: 7, scope: !107) -// CHECK:STDOUT: !115 = !DILocation(line: 51, column: 6, scope: !107) -// CHECK:STDOUT: !116 = !DILocation(line: 52, column: 12, scope: !107) -// CHECK:STDOUT: !117 = !DILocation(line: 52, column: 5, scope: !107) -// CHECK:STDOUT: !118 = !DILocation(line: 54, column: 12, scope: !107) -// CHECK:STDOUT: !119 = !DILocation(line: 54, column: 5, scope: !107) -// CHECK:STDOUT: !120 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.5bd8d5767580997a", scope: null, file: !1, line: 40, type: !60, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !121) +// CHECK:STDOUT: !111 = !DILocation(line: 49, column: 7, scope: !107) +// CHECK:STDOUT: !112 = !DILocation(line: 49, column: 6, scope: !107) +// CHECK:STDOUT: !113 = !DILocation(line: 50, column: 5, scope: !107) +// CHECK:STDOUT: !114 = !DILocation(line: 52, column: 7, scope: !107) +// CHECK:STDOUT: !115 = !DILocation(line: 52, column: 6, scope: !107) +// CHECK:STDOUT: !116 = !DILocation(line: 53, column: 12, scope: !107) +// CHECK:STDOUT: !117 = !DILocation(line: 53, column: 5, scope: !107) +// CHECK:STDOUT: !118 = !DILocation(line: 55, column: 12, scope: !107) +// CHECK:STDOUT: !119 = !DILocation(line: 55, column: 5, scope: !107) +// CHECK:STDOUT: !120 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.5bd8d5767580997a", scope: null, file: !1, line: 41, type: !60, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !121) // CHECK:STDOUT: !121 = !{!122, !123} // CHECK:STDOUT: !122 = !DILocalVariable(arg: 1, scope: !120, type: !30) // CHECK:STDOUT: !123 = !DILocalVariable(arg: 2, scope: !120, type: !30) -// CHECK:STDOUT: !124 = !DILocation(line: 41, column: 7, scope: !120) -// CHECK:STDOUT: !125 = !DILocation(line: 41, column: 6, scope: !120) -// CHECK:STDOUT: !126 = !DILocation(line: 42, column: 5, scope: !120) -// CHECK:STDOUT: !127 = !DILocation(line: 43, column: 10, scope: !120) -// CHECK:STDOUT: !128 = !DILocation(line: 43, column: 5, scope: !120) -// CHECK:STDOUT: !129 = !DILocation(line: 41, column: 3, scope: !120) -// CHECK:STDOUT: !130 = !DILocation(line: 40, column: 1, scope: !120) -// CHECK:STDOUT: !131 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.5bd8d5767580997a", scope: null, file: !1, line: 60, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !132) +// CHECK:STDOUT: !124 = !DILocation(line: 42, column: 7, scope: !120) +// CHECK:STDOUT: !125 = !DILocation(line: 42, column: 6, scope: !120) +// CHECK:STDOUT: !126 = !DILocation(line: 43, column: 5, scope: !120) +// CHECK:STDOUT: !127 = !DILocation(line: 44, column: 10, scope: !120) +// CHECK:STDOUT: !128 = !DILocation(line: 44, column: 5, scope: !120) +// CHECK:STDOUT: !129 = !DILocation(line: 42, column: 3, scope: !120) +// CHECK:STDOUT: !130 = !DILocation(line: 41, column: 1, scope: !120) +// CHECK:STDOUT: !131 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.5bd8d5767580997a", scope: null, file: !1, line: 61, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !132) // CHECK:STDOUT: !132 = !{!133, !134} // CHECK:STDOUT: !133 = !DILocalVariable(arg: 1, scope: !131, type: !30) // CHECK:STDOUT: !134 = !DILocalVariable(arg: 2, scope: !131, type: !30) -// CHECK:STDOUT: !135 = !DILocation(line: 61, column: 10, scope: !131) -// CHECK:STDOUT: !136 = !DILocation(line: 61, column: 3, scope: !131) -// CHECK:STDOUT: !137 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.5bd8d5767580997a", scope: null, file: !1, line: 64, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !138) +// CHECK:STDOUT: !135 = !DILocation(line: 62, column: 10, scope: !131) +// CHECK:STDOUT: !136 = !DILocation(line: 62, column: 3, scope: !131) +// CHECK:STDOUT: !137 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.5bd8d5767580997a", scope: null, file: !1, line: 65, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !138) // CHECK:STDOUT: !138 = !{!139, !140} // CHECK:STDOUT: !139 = !DILocalVariable(arg: 1, scope: !137, type: !30) // CHECK:STDOUT: !140 = !DILocalVariable(arg: 2, scope: !137, type: !30) -// CHECK:STDOUT: !141 = !DILocation(line: 65, column: 10, scope: !137) -// CHECK:STDOUT: !142 = !DILocation(line: 65, column: 3, scope: !137) -// CHECK:STDOUT: !143 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.c27b765f2159c9a0", scope: null, file: !1, line: 40, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !144) +// CHECK:STDOUT: !141 = !DILocation(line: 66, column: 10, scope: !137) +// CHECK:STDOUT: !142 = !DILocation(line: 66, column: 3, scope: !137) +// CHECK:STDOUT: !143 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.c27b765f2159c9a0", scope: null, file: !1, line: 41, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !144) // CHECK:STDOUT: !144 = !{!145, !146} // CHECK:STDOUT: !145 = !DILocalVariable(arg: 1, scope: !143, type: !23) // CHECK:STDOUT: !146 = !DILocalVariable(arg: 2, scope: !143, type: !30) -// CHECK:STDOUT: !147 = !DILocation(line: 41, column: 7, scope: !143) -// CHECK:STDOUT: !148 = !DILocation(line: 41, column: 6, scope: !143) -// CHECK:STDOUT: !149 = !DILocation(line: 42, column: 5, scope: !143) -// CHECK:STDOUT: !150 = !DILocation(line: 43, column: 10, scope: !143) -// CHECK:STDOUT: !151 = !DILocation(line: 43, column: 5, scope: !143) -// CHECK:STDOUT: !152 = !DILocation(line: 41, column: 3, scope: !143) -// CHECK:STDOUT: !153 = !DILocation(line: 40, column: 1, scope: !143) -// CHECK:STDOUT: !154 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.c27b765f2159c9a0", scope: null, file: !1, line: 60, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !155) +// CHECK:STDOUT: !147 = !DILocation(line: 42, column: 7, scope: !143) +// CHECK:STDOUT: !148 = !DILocation(line: 42, column: 6, scope: !143) +// CHECK:STDOUT: !149 = !DILocation(line: 43, column: 5, scope: !143) +// CHECK:STDOUT: !150 = !DILocation(line: 44, column: 10, scope: !143) +// CHECK:STDOUT: !151 = !DILocation(line: 44, column: 5, scope: !143) +// CHECK:STDOUT: !152 = !DILocation(line: 42, column: 3, scope: !143) +// CHECK:STDOUT: !153 = !DILocation(line: 41, column: 1, scope: !143) +// CHECK:STDOUT: !154 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.c27b765f2159c9a0", scope: null, file: !1, line: 61, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !155) // CHECK:STDOUT: !155 = !{!156, !157} // CHECK:STDOUT: !156 = !DILocalVariable(arg: 1, scope: !154, type: !23) // CHECK:STDOUT: !157 = !DILocalVariable(arg: 2, scope: !154, type: !30) -// CHECK:STDOUT: !158 = !DILocation(line: 61, column: 10, scope: !154) -// CHECK:STDOUT: !159 = !DILocation(line: 61, column: 3, scope: !154) -// CHECK:STDOUT: !160 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.c27b765f2159c9a0", scope: null, file: !1, line: 64, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !161) +// CHECK:STDOUT: !158 = !DILocation(line: 62, column: 10, scope: !154) +// CHECK:STDOUT: !159 = !DILocation(line: 62, column: 3, scope: !154) +// CHECK:STDOUT: !160 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.c27b765f2159c9a0", scope: null, file: !1, line: 65, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !161) // CHECK:STDOUT: !161 = !{!162, !163} // CHECK:STDOUT: !162 = !DILocalVariable(arg: 1, scope: !160, type: !23) // CHECK:STDOUT: !163 = !DILocalVariable(arg: 2, scope: !160, type: !30) -// CHECK:STDOUT: !164 = !DILocation(line: 65, column: 10, scope: !160) -// CHECK:STDOUT: !165 = !DILocation(line: 65, column: 3, scope: !160) -// CHECK:STDOUT: !166 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.2621742a01881e29", scope: null, file: !1, line: 40, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !167) +// CHECK:STDOUT: !164 = !DILocation(line: 66, column: 10, scope: !160) +// CHECK:STDOUT: !165 = !DILocation(line: 66, column: 3, scope: !160) +// CHECK:STDOUT: !166 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.2621742a01881e29", scope: null, file: !1, line: 41, type: !81, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !167) // CHECK:STDOUT: !167 = !{!168, !169} // CHECK:STDOUT: !168 = !DILocalVariable(arg: 1, scope: !166, type: !23) // CHECK:STDOUT: !169 = !DILocalVariable(arg: 2, scope: !166, type: !30) -// CHECK:STDOUT: !170 = !DILocation(line: 41, column: 7, scope: !166) -// CHECK:STDOUT: !171 = !DILocation(line: 41, column: 6, scope: !166) -// CHECK:STDOUT: !172 = !DILocation(line: 42, column: 5, scope: !166) -// CHECK:STDOUT: !173 = !DILocation(line: 43, column: 10, scope: !166) -// CHECK:STDOUT: !174 = !DILocation(line: 43, column: 5, scope: !166) -// CHECK:STDOUT: !175 = !DILocation(line: 41, column: 3, scope: !166) -// CHECK:STDOUT: !176 = !DILocation(line: 40, column: 1, scope: !166) -// CHECK:STDOUT: !177 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.2621742a01881e29", scope: null, file: !1, line: 60, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !178) +// CHECK:STDOUT: !170 = !DILocation(line: 42, column: 7, scope: !166) +// CHECK:STDOUT: !171 = !DILocation(line: 42, column: 6, scope: !166) +// CHECK:STDOUT: !172 = !DILocation(line: 43, column: 5, scope: !166) +// CHECK:STDOUT: !173 = !DILocation(line: 44, column: 10, scope: !166) +// CHECK:STDOUT: !174 = !DILocation(line: 44, column: 5, scope: !166) +// CHECK:STDOUT: !175 = !DILocation(line: 42, column: 3, scope: !166) +// CHECK:STDOUT: !176 = !DILocation(line: 41, column: 1, scope: !166) +// CHECK:STDOUT: !177 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.2621742a01881e29", scope: null, file: !1, line: 61, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !178) // CHECK:STDOUT: !178 = !{!179, !180} // CHECK:STDOUT: !179 = !DILocalVariable(arg: 1, scope: !177, type: !23) // CHECK:STDOUT: !180 = !DILocalVariable(arg: 2, scope: !177, type: !30) -// CHECK:STDOUT: !181 = !DILocation(line: 61, column: 10, scope: !177) -// CHECK:STDOUT: !182 = !DILocation(line: 61, column: 3, scope: !177) -// CHECK:STDOUT: !183 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.2621742a01881e29", scope: null, file: !1, line: 64, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !184) +// CHECK:STDOUT: !181 = !DILocation(line: 62, column: 10, scope: !177) +// CHECK:STDOUT: !182 = !DILocation(line: 62, column: 3, scope: !177) +// CHECK:STDOUT: !183 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.2621742a01881e29", scope: null, file: !1, line: 65, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !184) // CHECK:STDOUT: !184 = !{!185, !186} // CHECK:STDOUT: !185 = !DILocalVariable(arg: 1, scope: !183, type: !23) // CHECK:STDOUT: !186 = !DILocalVariable(arg: 2, scope: !183, type: !30) -// CHECK:STDOUT: !187 = !DILocation(line: 65, column: 10, scope: !183) -// CHECK:STDOUT: !188 = !DILocation(line: 65, column: 3, scope: !183) -// CHECK:STDOUT: !189 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.5bd8d5767580997a", scope: null, file: !1, line: 68, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !190) +// CHECK:STDOUT: !187 = !DILocation(line: 66, column: 10, scope: !183) +// CHECK:STDOUT: !188 = !DILocation(line: 66, column: 3, scope: !183) +// CHECK:STDOUT: !189 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.5bd8d5767580997a", scope: null, file: !1, line: 69, type: !35, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !190) // CHECK:STDOUT: !190 = !{!191, !192} // CHECK:STDOUT: !191 = !DILocalVariable(arg: 1, scope: !189, type: !30) // CHECK:STDOUT: !192 = !DILocalVariable(arg: 2, scope: !189, type: !30) -// CHECK:STDOUT: !193 = !DILocation(line: 69, column: 15, scope: !189) -// CHECK:STDOUT: !194 = !DILocation(line: 69, column: 10, scope: !189) -// CHECK:STDOUT: !195 = !DILocation(line: 69, column: 3, scope: !189) -// CHECK:STDOUT: !196 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c27b765f2159c9a0", scope: null, file: !1, line: 68, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !197) +// CHECK:STDOUT: !193 = !DILocation(line: 70, column: 15, scope: !189) +// CHECK:STDOUT: !194 = !DILocation(line: 70, column: 10, scope: !189) +// CHECK:STDOUT: !195 = !DILocation(line: 70, column: 3, scope: !189) +// CHECK:STDOUT: !196 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c27b765f2159c9a0", scope: null, file: !1, line: 69, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !197) // CHECK:STDOUT: !197 = !{!198, !199} // CHECK:STDOUT: !198 = !DILocalVariable(arg: 1, scope: !196, type: !23) // CHECK:STDOUT: !199 = !DILocalVariable(arg: 2, scope: !196, type: !30) -// CHECK:STDOUT: !200 = !DILocation(line: 69, column: 15, scope: !196) -// CHECK:STDOUT: !201 = !DILocation(line: 69, column: 10, scope: !196) -// CHECK:STDOUT: !202 = !DILocation(line: 69, column: 3, scope: !196) -// CHECK:STDOUT: !203 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.2621742a01881e29", scope: null, file: !1, line: 68, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !204) +// CHECK:STDOUT: !200 = !DILocation(line: 70, column: 15, scope: !196) +// CHECK:STDOUT: !201 = !DILocation(line: 70, column: 10, scope: !196) +// CHECK:STDOUT: !202 = !DILocation(line: 70, column: 3, scope: !196) +// CHECK:STDOUT: !203 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.2621742a01881e29", scope: null, file: !1, line: 69, type: !44, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !204) // CHECK:STDOUT: !204 = !{!205, !206} // CHECK:STDOUT: !205 = !DILocalVariable(arg: 1, scope: !203, type: !23) // CHECK:STDOUT: !206 = !DILocalVariable(arg: 2, scope: !203, type: !30) -// CHECK:STDOUT: !207 = !DILocation(line: 69, column: 15, scope: !203) -// CHECK:STDOUT: !208 = !DILocation(line: 69, column: 10, scope: !203) -// CHECK:STDOUT: !209 = !DILocation(line: 69, column: 3, scope: !203) +// CHECK:STDOUT: !207 = !DILocation(line: 70, column: 15, scope: !203) +// CHECK:STDOUT: !208 = !DILocation(line: 70, column: 10, scope: !203) +// CHECK:STDOUT: !209 = !DILocation(line: 70, column: 3, scope: !203) // CHECK:STDOUT: diff --git a/toolchain/runtimes/BUILD b/toolchain/runtimes/BUILD index e1dbdb447cd2..1e8790254b5e 100644 --- a/toolchain/runtimes/BUILD +++ b/toolchain/runtimes/BUILD @@ -204,6 +204,13 @@ filegroup( ], ) +filegroup( + name = "carbon_core", + srcs = [ + "//core:prelude_files", + ], +) + # Currently, we're only installing the subset of LLVM's libc internals needed to # build libc++. At some point, we should ship LLVM's libc itself, and that will # likely expand this to cover more of the source. However, we'll still want to diff --git a/toolchain/runtimes/carbon_runtimes.bzl b/toolchain/runtimes/carbon_runtimes.bzl index e870bb9440e1..7ba39a1ad985 100644 --- a/toolchain/runtimes/carbon_runtimes.bzl +++ b/toolchain/runtimes/carbon_runtimes.bzl @@ -48,6 +48,7 @@ CarbonRuntimesConfigInfo = provider( """, fields = [ "builtins_archive", + "carbon_prelude_prebuilt", "clang_hdrs_prefix", "crt_copts", "crtbegin_src", @@ -63,6 +64,7 @@ def _carbon_runtimes_config_impl(ctx): return [ CarbonRuntimesConfigInfo( builtins_archive = ctx.files.builtins_archive[0], + carbon_prelude_prebuilt = ctx.files.carbon_prelude_prebuilt, clang_hdrs_prefix = ctx.attr.clang_hdrs_prefix, crt_copts = ctx.attr.crt_copts, crtbegin_src = ctx.files.crtbegin_src[0] if ctx.files.crtbegin_src else None, @@ -78,6 +80,7 @@ carbon_runtimes_config = rule( implementation = _carbon_runtimes_config_impl, attrs = { "builtins_archive": attr.label(mandatory = True, allow_files = [".a"]), + "carbon_prelude_prebuilt": attr.label(allow_files = [".o"]), "clang_hdrs_prefix": attr.string(default = "include/"), "crt_copts": attr.string_list(default = []), "crtbegin_src": attr.label(allow_files = [".c"]), @@ -170,6 +173,14 @@ def _carbon_runtimes_build_impl(ctx): ctx.actions.symlink(output = out_hdr, target_file = hdr) outputs.append(out_hdr) + for obj in config.carbon_prelude_prebuilt: + rel_path = obj.path + out_obj = ctx.actions.declare_file( + "{0}/core/{1}".format(prefix, rel_path), + ) + ctx.actions.symlink(output = out_obj, target_file = obj) + outputs.append(out_obj) + return [DefaultInfo(files = depset(outputs))] carbon_runtimes_build = rule( diff --git a/toolchain/testing/file_test.cpp b/toolchain/testing/file_test.cpp index 946c8304d0f4..44b09b096d61 100644 --- a/toolchain/testing/file_test.cpp +++ b/toolchain/testing/file_test.cpp @@ -47,6 +47,9 @@ struct SharedTestData { // Files in the prelude. llvm::SmallVector prelude_files; + // Files in core not in the prelude. + llvm::SmallVector core_files; + // The installed files that tests can use. llvm::IntrusiveRefCntPtr file_system = new llvm::vfs::InMemoryFileSystem(); @@ -63,6 +66,12 @@ static auto GetSharedTestData(llvm::StringRef exe_path) CARBON_RETURN_IF_ERROR(AddFile(*data.file_system, file)); } + CARBON_ASSIGN_OR_RETURN(data.core_files, + data.installation.ReadCarbonCoreManifest()); + for (const auto& file : data.core_files) { + CARBON_RETURN_IF_ERROR(AddFile(*data.file_system, file)); + } + llvm::SmallVector clang_header_files; CARBON_ASSIGN_OR_RETURN(clang_header_files, data.installation.ReadClangHeadersManifest()); @@ -166,6 +175,7 @@ auto ToolchainFileTest::Run( if (component_ == "check" || component_ == "lower") { filtered_test_args.reserve(test_args.size()); bool found_prelude_flag = false; + bool found_include_core_flag = false; for (auto arg : test_args) { bool driver_flag = arg == "--custom-core" || arg == "--no-prelude-import"; // A flag specified by a test prelude to indicate the intention to include @@ -174,7 +184,9 @@ auto ToolchainFileTest::Run( if (driver_flag || full_prelude) { found_prelude_flag = true; } - if (!full_prelude) { + bool include_core = arg == "--include-carbon-core"; + found_include_core_flag |= include_core; + if (!full_prelude && !include_core) { filtered_test_args.push_back(arg); } } @@ -183,6 +195,13 @@ auto ToolchainFileTest::Run( "Include a prelude from //toolchain/testing/testdata/min_prelude " "to specify what should be imported into the test."); } + // The compile driver includes the carbon-core by default, but we invert + // this logic for the check and lower phases, meaning we detect the presence + // of `--include-carbon-core` in the arguments, and unless that is there + // we automatically append the `--no-include-carbon-core` flag. + if (!found_include_core_flag) { + filtered_test_args.push_back("--no-include-carbon-core"); + } } else { filtered_test_args = test_args; } @@ -266,7 +285,7 @@ auto ToolchainFileTest::GetDefaultArgs() const } else if (component_ == "lower") { args.insert(args.end(), {"--dump-llvm-ir", "--target=x86_64-linux-gnu"}); } else if (component_ == "codegen") { - // codegen tests specify flags as needed. + args.insert(args.end(), {"--no-include-carbon-core"}); } else { CARBON_FATAL("Unexpected test component {0}: {1}", component_, test_name()); }