diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index 164481102be37..ec5cc9b899009 100644 --- a/toolchain/driver/BUILD +++ b/toolchain/driver/BUILD @@ -22,6 +22,7 @@ cc_library( "//toolchain/lowering:lower_to_llvm", "//toolchain/parser:parse_tree", "//toolchain/semantics:semantics_ir", + "//toolchain/semantics:semantics_ir_formatter", "//toolchain/source:source_buffer", "@llvm-project//llvm:Core", "@llvm-project//llvm:Support", diff --git a/toolchain/driver/driver.cpp b/toolchain/driver/driver.cpp index 75dfd1566c1c0..a6d2db23521ef 100644 --- a/toolchain/driver/driver.cpp +++ b/toolchain/driver/driver.cpp @@ -19,6 +19,7 @@ #include "toolchain/lowering/lower_to_llvm.h" #include "toolchain/parser/parse_tree.h" #include "toolchain/semantics/semantics_ir.h" +#include "toolchain/semantics/semantics_ir_formatter.h" #include "toolchain/source/source_buffer.h" namespace Carbon { @@ -116,6 +117,7 @@ auto Driver::RunHelpSubcommand(DiagnosticConsumer& /*consumer*/, enum class DumpMode { TokenizedBuffer, ParseTree, + RawSemanticsIR, SemanticsIR, LLVMIR, Assembly, @@ -133,6 +135,7 @@ auto Driver::RunDumpSubcommand(DiagnosticConsumer& consumer, auto dump_mode = llvm::StringSwitch(args.front()) .Case("tokens", DumpMode::TokenizedBuffer) .Case("parse-tree", DumpMode::ParseTree) + .Case("raw-semantics-ir", DumpMode::RawSemanticsIR) .Case("semantics-ir", DumpMode::SemanticsIR) .Case("llvm-ir", DumpMode::LLVMIR) .Case("assembly", DumpMode::Assembly) @@ -152,9 +155,16 @@ auto Driver::RunDumpSubcommand(DiagnosticConsumer& consumer, parse_tree_preorder = true; } - bool semantics_ir_include_builtins = false; + bool semantics_ir_include_raw = false; if (dump_mode == DumpMode::SemanticsIR && !args.empty() && - args.front() == "--include_builtins") { + args.front() == "--include_raw") { + args = args.drop_front(); + semantics_ir_include_raw = true; + } + + bool semantics_ir_include_builtins = false; + if ((dump_mode == DumpMode::RawSemanticsIR || semantics_ir_include_raw) && + !args.empty() && args.front() == "--include_builtins") { args = args.drop_front(); semantics_ir_include_builtins = true; } @@ -239,10 +249,19 @@ auto Driver::RunDumpSubcommand(DiagnosticConsumer& consumer, builtin_ir, tokenized_source, parse_tree, consumer, vlog_stream_); has_errors |= semantics_ir.has_errors(); CARBON_VLOG() << "*** SemanticsIR::MakeFromParseTree done ***\n"; - if (dump_mode == DumpMode::SemanticsIR) { + if (dump_mode == DumpMode::RawSemanticsIR) { semantics_ir.Print(output_stream_, semantics_ir_include_builtins); return !has_errors; } + if (dump_mode == DumpMode::SemanticsIR) { + if (semantics_ir_include_raw) { + semantics_ir.Print(output_stream_, semantics_ir_include_builtins); + output_stream_ << "\n"; + } + FormatSemanticsIR(tokenized_source, parse_tree, semantics_ir, + output_stream_); + return !has_errors; + } CARBON_VLOG() << "semantics_ir: " << semantics_ir; // Unlike previous steps, errors block further progress. diff --git a/toolchain/semantics/BUILD b/toolchain/semantics/BUILD index af352d82ec86b..36243ab0ac9e8 100644 --- a/toolchain/semantics/BUILD +++ b/toolchain/semantics/BUILD @@ -95,6 +95,23 @@ cc_library( ], ) +cc_library( + name = "semantics_ir_formatter", + srcs = [ + "semantics_ir_formatter.cpp", + ], + hdrs = [ + "semantics_ir_formatter.h", + ], + deps = [ + ":semantics_ir", + ":semantics_node_kind", + "//toolchain/lexer:tokenized_buffer", + "//toolchain/parser:parse_tree", + "@llvm-project//llvm:Support", + ], +) + cc_test( name = "semantics_ir_test", size = "small", diff --git a/toolchain/semantics/semantics_file_test.cpp b/toolchain/semantics/semantics_file_test.cpp index eb7eeabae9041..efe7445f7ba3c 100644 --- a/toolchain/semantics/semantics_file_test.cpp +++ b/toolchain/semantics/semantics_file_test.cpp @@ -15,7 +15,8 @@ class SemanticsFileTest : public DriverFileTestBase { using DriverFileTestBase::DriverFileTestBase; auto GetDefaultArgs() -> llvm::SmallVector override { - return {"dump", "semantics-ir", "%s"}; + // TODO: Remove the "--include_raw" once the textual IR format stabilizes. + return {"dump", "semantics-ir", "--include_raw", "%s"}; } }; diff --git a/toolchain/semantics/semantics_handle_function.cpp b/toolchain/semantics/semantics_handle_function.cpp index cbd4a9d02c580..e6d7cd2eb492e 100644 --- a/toolchain/semantics/semantics_handle_function.cpp +++ b/toolchain/semantics/semantics_handle_function.cpp @@ -27,7 +27,11 @@ static auto BuildFunctionDeclaration(SemanticsContext& context) // Add the callable. auto function_id = context.semantics_ir().AddFunction( - {.name_id = name_context.unresolved_name_id, + {.name_id = + name_context.state == + SemanticsDeclarationNameStack::Context::State::Unresolved + ? name_context.unresolved_name_id + : SemanticsStringId(SemanticsStringId::InvalidIndex), .param_refs_id = param_refs_id, .return_type_id = return_type_id, .body_block_ids = {}}); diff --git a/toolchain/semantics/semantics_ir.cpp b/toolchain/semantics/semantics_ir.cpp index 2301160002e2f..42b6aaeb86d5d 100644 --- a/toolchain/semantics/semantics_ir.cpp +++ b/toolchain/semantics/semantics_ir.cpp @@ -5,6 +5,9 @@ #include "toolchain/semantics/semantics_ir.h" #include "common/check.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/SaveAndRestore.h" #include "toolchain/common/pretty_stack_trace_function.h" #include "toolchain/parser/parse_tree_node_location_translator.h" #include "toolchain/semantics/semantics_builtin_kind.h" @@ -248,7 +251,8 @@ static auto GetTypePrecedence(SemanticsNodeKind kind) -> int { } } -auto SemanticsIR::StringifyType(SemanticsTypeId type_id) -> std::string { +auto SemanticsIR::StringifyType(SemanticsTypeId type_id, + bool in_type_context) const -> std::string { std::string str; llvm::raw_string_ostream out(str); @@ -396,12 +400,14 @@ auto SemanticsIR::StringifyType(SemanticsTypeId type_id) -> std::string { } // For `{}` or any tuple type, we've printed a non-type expression, so add a - // conversion to type `type`. - auto outer_node = GetNode(outer_node_id); - if (outer_node.kind() == SemanticsNodeKind::TupleType || - (outer_node.kind() == SemanticsNodeKind::StructType && - GetNodeBlock(outer_node.GetAsStructType()).empty())) { - out << " as type"; + // conversion to type `type` if it's not implied by the context. + if (!in_type_context) { + auto outer_node = GetNode(outer_node_id); + if (outer_node.kind() == SemanticsNodeKind::TupleType || + (outer_node.kind() == SemanticsNodeKind::StructType && + GetNodeBlock(outer_node.GetAsStructType()).empty())) { + out << " as type"; + } } return str; diff --git a/toolchain/semantics/semantics_ir.h b/toolchain/semantics/semantics_ir.h index 04efae736a31a..ee208fe6e3e3b 100644 --- a/toolchain/semantics/semantics_ir.h +++ b/toolchain/semantics/semantics_ir.h @@ -96,7 +96,8 @@ class SemanticsIR { } // Returns the requested callable. - auto GetFunction(SemanticsFunctionId function_id) const -> SemanticsFunction { + auto GetFunction(SemanticsFunctionId function_id) const + -> const SemanticsFunction& { return functions_[function_id.index]; } @@ -135,7 +136,7 @@ class SemanticsIR { } // Returns the requested name scope. - auto GetNameScope(SemanticsNameScopeId scope_id) + auto GetNameScope(SemanticsNameScopeId scope_id) const -> const llvm::DenseMap& { return name_scopes_[scope_id.index]; } @@ -266,11 +267,16 @@ class SemanticsIR { return type_blocks_[block_id.index]; } - // Produces a string version of a type. - auto StringifyType(SemanticsTypeId type_id) -> std::string; + // Produces a string version of a type. If `in_type_context` is false, an + // explicit conversion to type `type` will be added in cases where the type + // expression would otherwise have a different type, such as a tuple or + // struct type. + auto StringifyType(SemanticsTypeId type_id, + bool in_type_context = false) const -> std::string; auto functions_size() const -> int { return functions_.size(); } auto nodes_size() const -> int { return nodes_.size(); } + auto node_blocks_size() const -> int { return node_blocks_.size(); } auto types() const -> const llvm::SmallVector& { return types_; diff --git a/toolchain/semantics/semantics_ir_formatter.cpp b/toolchain/semantics/semantics_ir_formatter.cpp new file mode 100644 index 0000000000000..7caab129457fb --- /dev/null +++ b/toolchain/semantics/semantics_ir_formatter.cpp @@ -0,0 +1,671 @@ +// 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/semantics/semantics_ir_formatter.h" + +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/Support/SaveAndRestore.h" +#include "toolchain/lexer/tokenized_buffer.h" +#include "toolchain/parser/parse_tree.h" + +namespace Carbon { + +namespace { +// Assigns names to nodes, blocks, and scopes in the Semantics IR. +// +// TODOs / future work ideas: +// - Add a documentation file for the textual format and link to the +// naming section here. +// - Consider harmonizing `FooLiteral` vs. `foo_value` node names vs. +// IR names. +// - Also consider representing these as just `value` or `literal` +// in the IR and using the type to distinguish. +// - Add block names based on the control flow construct names (`for`, +// `if`, `then`, `else`, ...). Either base this on the semantics or +// just on the keywords used to build that control flow -- little +// or no harm to getting it wrong. Tools will also want to be able +// to query the construct that resulted in control flow. +class NodeNamer { + public: + enum class ScopeIndex : int { + None = -1, + Package = 0, + }; + + NodeNamer(const TokenizedBuffer& tokenized_buffer, + const ParseTree& parse_tree, const SemanticsIR& semantics_ir) + : tokenized_buffer_(tokenized_buffer), + parse_tree_(parse_tree), + semantics_ir_(semantics_ir) { + nodes.resize(semantics_ir.nodes_size()); + labels.resize(semantics_ir.node_blocks_size()); + scopes.resize(1 + semantics_ir.functions_size()); + + // Build the package scope. + GetScopeInfo(ScopeIndex::Package).name = + globals.AddNameUnchecked("package"); + CollectNamesInBlock(ScopeIndex::Package, semantics_ir.top_node_block_id()); + + // Build each function scope. + for (int i = 0; i != semantics_ir.functions_size(); ++i) { + auto fn_id = SemanticsFunctionId(i); + auto fn_scope = GetScopeFor(fn_id); + const auto& fn = semantics_ir.GetFunction(fn_id); + GetScopeInfo(fn_scope).name = globals.AllocateName( + *this, + // TODO: Provide a location for the function for use as a + // disambiguator. + ParseTree::Node::Invalid, + fn.name_id.is_valid() ? semantics_ir.GetString(fn.name_id).str() + : ""); + CollectNamesInBlock(fn_scope, fn.param_refs_id); + for (auto block_id : fn.body_block_ids) { + AddBlockLabel(fn_scope, block_id, + block_id == fn.body_block_ids.front() ? "entry" : ""); + CollectNamesInBlock(fn_scope, block_id); + } + } + } + + // Returns the scope index corresponding to a function. + auto GetScopeFor(SemanticsFunctionId fn_id) -> ScopeIndex { + return ScopeIndex(fn_id.index + 1); + } + + // Returns the IR name to use for a function. + auto GetNameFor(SemanticsFunctionId fn_id) -> llvm::StringRef { + if (!fn_id.is_valid()) { + return "invalid"; + } + return GetScopeInfo(GetScopeFor(fn_id)).name; + } + + // Returns the IR name to use for a node, when referenced from a given scope. + auto GetNameFor(ScopeIndex scope_idx, SemanticsNodeId node_id) + -> std::string { + if (!node_id.is_valid()) { + return "invalid"; + } + + // Check for a builtin. + if (node_id.index < SemanticsBuiltinKind::ValidCount) { + return SemanticsBuiltinKind::FromInt(node_id.index).label().str(); + } + + auto& [node_scope, node_name] = nodes[node_id.index]; + if (!node_name) { + // This should not happen in valid IR. + return ""; + } + if (node_scope == scope_idx) { + return node_name.str().str(); + } + return (GetScopeInfo(node_scope).name.str() + "." + node_name.str()).str(); + } + + // Returns the IR name to use for a label, when referenced from a given scope. + auto GetLabelFor(ScopeIndex scope_idx, SemanticsNodeBlockId block_id) + -> std::string { + if (!block_id.is_valid()) { + return "!invalid"; + } + + auto& [label_scope, label_name] = labels[block_id.index]; + if (!label_name) { + // This should not happen in valid IR. + return ""; + } + if (label_scope == scope_idx) { + return label_name.str().str(); + } + return (GetScopeInfo(label_scope).name.str() + "." + label_name.str()) + .str(); + } + + private: + // A space in which unique names can be allocated. + struct Namespace { + // A result of a name lookup. + struct NameResult; + + // A name in a namespace, which might be redirected to refer to another name + // for disambiguation purposes. + class Name { + public: + Name() : value_(nullptr) {} + explicit Name(llvm::StringMapIterator it) : value_(&*it) {} + + explicit operator bool() const { return value_; } + + auto str() const -> llvm::StringRef { + llvm::StringMapEntry* value = value_; + CARBON_CHECK(value) << "cannot print a null name"; + while (value->second.ambiguous && value->second.fallback) { + value = value->second.fallback.value_; + } + return value->first(); + } + + operator llvm::StringRef() const { return str(); } + + auto SetFallback(Name name) -> void { value_->second.fallback = name; } + + auto SetAmbiguous() -> void { value_->second.ambiguous = true; } + + private: + llvm::StringMapEntry* value_; + }; + + struct NameResult { + bool ambiguous = false; + Name fallback = Name(); + }; + + llvm::StringRef prefix; + llvm::StringMap allocated = {}; + int unnamed_count = 0; + + auto AddNameUnchecked(llvm::StringRef name) -> Name { + return Name(allocated.insert({name, NameResult()}).first); + } + + auto AllocateName(const NodeNamer& namer, ParseTree::Node node, + std::string name = "") -> Name { + // The best (shortest) name for this node so far, and the current name + // for it. + Name best; + Name current; + + // Add `name` as a name for this entity. + auto add_name = [&](bool mark_ambiguous = true) { + auto [it, added] = allocated.insert({name, NameResult()}); + Name new_name = Name(it); + + if (!added) { + if (mark_ambiguous) { + // This name was allocated for a different node. Mark it as + // ambiguous and keep looking for a name for this node. + new_name.SetAmbiguous(); + } + } else { + if (!best) { + best = new_name; + } else { + CARBON_CHECK(current); + current.SetFallback(new_name); + } + current = new_name; + } + return added; + }; + + // All names start with the prefix. + name.insert(0, prefix); + + // Use the given name if it's available and not just the prefix. + if (name.size() > prefix.size()) { + add_name(); + } + + // Append location information to try to disambiguate. + if (node.is_valid()) { + auto token = namer.parse_tree_.node_token(node); + llvm::raw_string_ostream(name) + << ".loc" << namer.tokenized_buffer_.GetLineNumber(token); + add_name(); + + llvm::raw_string_ostream(name) + << "_" << namer.tokenized_buffer_.GetColumnNumber(token); + add_name(); + } + + // Append numbers until we find an available name. + name += "."; + auto name_size_without_counter = name.size(); + for (int counter = 1;; ++counter) { + name.resize(name_size_without_counter); + llvm::raw_string_ostream(name) << counter; + if (add_name(/*mark_ambiguous=*/false)) { + return best; + } + } + } + }; + + // A named scope that contains named entities. + struct Scope { + Namespace::Name name; + Namespace nodes = {.prefix = "%"}; + Namespace labels = {.prefix = "!"}; + }; + + auto GetScopeInfo(ScopeIndex scope_idx) -> Scope& { + return scopes[(int)scope_idx]; + } + + auto AddBlockLabel(ScopeIndex scope_idx, SemanticsNodeBlockId block_id, + std::string name = "") -> void { + if (!block_id.is_valid()) { + return; + } + + ParseTree::Node parse_node = ParseTree::Node::Invalid; + if (auto& block = semantics_ir_.GetNodeBlock(block_id); !block.empty()) { + parse_node = semantics_ir_.GetNode(block.front()).parse_node(); + } + + labels[block_id.index] = {scope_idx, + GetScopeInfo(scope_idx).labels.AllocateName( + *this, parse_node, std::move(name))}; + } + + auto CollectNamesInBlock(ScopeIndex scope_idx, SemanticsNodeBlockId block_id) + -> void { + if (!block_id.is_valid()) { + return; + } + + Scope& scope = GetScopeInfo(scope_idx); + + // Use bound names where available. The BindName node appears after the node + // that it's giving a name to, so we need to do this before assigning + // fallback names. + for (auto node_id : semantics_ir_.GetNodeBlock(block_id)) { + auto node = semantics_ir_.GetNode(node_id); + if (node.kind() == SemanticsNodeKind::BindName) { + auto [name_id, named_node_id] = node.GetAsBindName(); + nodes[named_node_id.index] = { + scope_idx, + scope.nodes.AllocateName(*this, node.parse_node(), + semantics_ir_.GetString(name_id).str())}; + } + } + + // Sequentially number all remaining values. + for (auto node_id : semantics_ir_.GetNodeBlock(block_id)) { + auto node = semantics_ir_.GetNode(node_id); + if (node.kind() != SemanticsNodeKind::BindName && + node.kind().value_kind() != SemanticsNodeValueKind::None) { + auto& name = nodes[node_id.index]; + if (!name.second) { + name = {scope_idx, + scope.nodes.AllocateName(*this, node.parse_node())}; + } + } + } + } + + const TokenizedBuffer& tokenized_buffer_; + const ParseTree& parse_tree_; + const SemanticsIR& semantics_ir_; + + Namespace globals = {.prefix = "@"}; + std::vector> nodes; + std::vector> labels; + std::vector scopes; +}; +} // namespace + +// Formatter for printing textual Semantics IR. +class SemanticsIRFormatter { + public: + explicit SemanticsIRFormatter(const TokenizedBuffer& tokenized_buffer, + const ParseTree& parse_tree, + const SemanticsIR& semantics_ir, + llvm::raw_ostream& out) + : semantics_ir_(semantics_ir), + out_(out), + node_namer_(tokenized_buffer, parse_tree, semantics_ir) {} + + auto Format() -> void { + // TODO: Include information from the package declaration, once we fully + // support it. + out_ << "package {\n"; + // TODO: Handle the case where there are multiple top-level node blocks. + // For example, there may be branching in the initializer of a global or a + // type expression. + if (auto block_id = semantics_ir_.top_node_block_id(); + block_id.is_valid()) { + llvm::SaveAndRestore package_scope(scope_, + NodeNamer::ScopeIndex::Package); + FormatCodeBlock(block_id); + } + out_ << "}\n"; + + for (int i = 0; i != semantics_ir_.functions_size(); ++i) { + FormatFunction(SemanticsFunctionId(i)); + } + } + + auto FormatFunction(SemanticsFunctionId id) -> void { + const SemanticsFunction& fn = semantics_ir_.GetFunction(id); + + out_ << "\nfn "; + FormatFunctionName(id); + out_ << "("; + + llvm::SaveAndRestore function_scope(scope_, node_namer_.GetScopeFor(id)); + + llvm::ListSeparator sep; + for (const SemanticsNodeId param_id : + semantics_ir_.GetNodeBlock(fn.param_refs_id)) { + out_ << sep; + auto param = semantics_ir_.GetNode(param_id); + auto [name_id, node_id] = param.GetAsBindName(); + FormatNodeName(node_id); + out_ << ": "; + FormatType(param.type_id()); + } + out_ << ")"; + if (fn.return_type_id.is_valid()) { + out_ << " -> "; + FormatType(fn.return_type_id); + } + + if (!fn.body_block_ids.empty()) { + out_ << " {"; + + for (auto block_id : fn.body_block_ids) { + out_ << "\n"; + + FormatLabel(block_id); + out_ << ":\n"; + + FormatCodeBlock(block_id); + } + + out_ << "}\n"; + } else { + out_ << ";\n"; + } + } + + auto FormatCodeBlock(SemanticsNodeBlockId block_id) -> void { + if (!block_id.is_valid()) { + return; + } + + for (const SemanticsNodeId node_id : semantics_ir_.GetNodeBlock(block_id)) { + FormatInstruction(node_id); + } + } + + auto FormatInstruction(SemanticsNodeId node_id) -> void { + if (!node_id.is_valid()) { + out_ << " " << SemanticsNodeKind::Invalid.ir_name() << "\n"; + return; + } + + FormatInstruction(node_id, semantics_ir_.GetNode(node_id)); + } + + auto FormatInstruction(SemanticsNodeId node_id, SemanticsNode node) -> void { + switch (node.kind()) { +#define CARBON_SEMANTICS_NODE_KIND(Name) \ + case SemanticsNodeKind::Name: \ + FormatInstruction(node_id, node); \ + break; +#include "toolchain/semantics/semantics_node_kind.def" + } + } + + template + auto FormatInstruction(SemanticsNodeId node_id, SemanticsNode node) -> void { + out_ << " "; + FormatInstructionLHS(node_id, node); + out_ << node.kind().ir_name(); + FormatInstructionRHS(node); + out_ << "\n"; + } + + auto FormatInstructionLHS(SemanticsNodeId node_id, SemanticsNode node) + -> void { + switch (node.kind().value_kind()) { + case SemanticsNodeValueKind::Typed: + FormatNodeName(node_id); + out_ << ": "; + FormatType(node.type_id()); + out_ << " = "; + break; + case SemanticsNodeValueKind::Untyped: + FormatNodeName(node_id); + out_ << " = "; + break; + case SemanticsNodeValueKind::None: + break; + } + } + + template + auto FormatInstructionRHS(SemanticsNode node) -> void { + // By default, an instruction has a comma-separated argument list. + FormatArgs(Kind::Get(node)); + } + + // BindName is handled by the NodeNamer and doesn't appear in the output. + // These nodes are currently used simply to give a name to another node, and + // are never referenced themselves. + // TODO: Include BindName nodes in the output if we start referring to them. + template <> + auto FormatInstruction(SemanticsNodeId, + SemanticsNode) -> void {} + + template <> + auto FormatInstructionRHS(SemanticsNode node) + -> void { + out_ << " "; + FormatLabel(node.GetAsBlockArg()); + } + + template <> + auto FormatInstruction(SemanticsNodeId, + SemanticsNode node) -> void { + if (!in_terminator_sequence) { + out_ << " "; + } + auto [label_id, cond_id] = node.GetAsBranchIf(); + out_ << "if "; + FormatNodeName(cond_id); + out_ << " " << SemanticsNodeKind::Branch.ir_name() << " "; + FormatLabel(label_id); + out_ << " else "; + in_terminator_sequence = true; + } + + template <> + auto FormatInstruction(SemanticsNodeId, + SemanticsNode node) + -> void { + if (!in_terminator_sequence) { + out_ << " "; + } + auto [label_id, arg_id] = node.GetAsBranchWithArg(); + out_ << SemanticsNodeKind::BranchWithArg.ir_name() << " "; + FormatLabel(label_id); + out_ << "("; + FormatNodeName(arg_id); + out_ << ")\n"; + in_terminator_sequence = false; + } + + template <> + auto FormatInstruction(SemanticsNodeId, + SemanticsNode node) -> void { + if (!in_terminator_sequence) { + out_ << " "; + } + out_ << SemanticsNodeKind::Branch.ir_name() << " "; + FormatLabel(node.GetAsBranch()); + out_ << "\n"; + in_terminator_sequence = false; + } + + template <> + auto FormatInstructionRHS(SemanticsNode node) -> void { + out_ << " "; + auto [args_id, callee_id] = node.GetAsCall(); + FormatArg(callee_id); + FormatArg(args_id); + } + + template <> + auto FormatInstructionRHS(SemanticsNode node) + -> void { + // TODO: Figure out a way to make this meaningful. We'll need some way to + // name cross-reference IRs, perhaps by the node ID of the import? + auto [xref_id, node_id] = node.GetAsCrossReference(); + out_ << " " << xref_id << "." << node_id; + } + + // StructTypeFields are formatted as part of their StructType. + template <> + auto FormatInstruction(SemanticsNodeId, + SemanticsNode) + -> void {} + + template <> + auto FormatInstructionRHS(SemanticsNode node) + -> void { + out_ << " {"; + llvm::ListSeparator sep; + for (auto field_id : semantics_ir_.GetNodeBlock(node.GetAsStructType())) { + out_ << sep << "."; + auto [field_name_id, field_type_id] = + semantics_ir_.GetNode(field_id).GetAsStructTypeField(); + FormatString(field_name_id); + out_ << ": "; + FormatType(field_type_id); + } + out_ << "}"; + } + + auto FormatArgs(SemanticsNode::NoArgs) -> void {} + + template + auto FormatArgs(Arg1 arg) -> void { + out_ << ' '; + FormatArg(arg); + } + + template + auto FormatArgs(std::pair args) -> void { + out_ << ' '; + FormatArg(args.first); + out_ << ","; + FormatArgs(args.second); + } + + auto FormatArg(SemanticsBoolValue v) -> void { out_ << v; } + + auto FormatArg(SemanticsBuiltinKind kind) -> void { out_ << kind.label(); } + + auto FormatArg(SemanticsFunctionId id) -> void { FormatFunctionName(id); } + + auto FormatArg(SemanticsIntegerLiteralId id) -> void { + out_ << semantics_ir_.GetIntegerLiteral(id); + } + + auto FormatArg(SemanticsMemberIndex index) -> void { out_ << index; } + + // TODO: Should we be printing scopes inline, or should we have a separate + // step to print them like we do for functions? + auto FormatArg(SemanticsNameScopeId id) -> void { + // Name scopes aren't kept in any particular order. Sort the entries before + // we print them for stability and consistency. + std::vector> entries; + for (auto [name_id, node_id] : semantics_ir_.GetNameScope(id)) { + entries.push_back({node_id, name_id}); + } + llvm::sort(entries, + [](auto a, auto b) { return a.first.index < b.first.index; }); + + out_ << '{'; + llvm::ListSeparator sep; + for (auto [node_id, name_id] : entries) { + out_ << sep << "."; + FormatString(name_id); + out_ << " = "; + FormatNodeName(node_id); + } + out_ << '}'; + } + + auto FormatArg(SemanticsNodeId id) -> void { FormatNodeName(id); } + + auto FormatArg(SemanticsNodeBlockId id) -> void { + out_ << '('; + llvm::ListSeparator sep; + for (auto node_id : semantics_ir_.GetNodeBlock(id)) { + out_ << sep; + FormatArg(node_id); + } + out_ << ')'; + } + + auto FormatArg(SemanticsRealLiteralId id) -> void { + // TODO: Format with a `.` when the exponent is near zero. + const auto& real = semantics_ir_.GetRealLiteral(id); + out_ << real.mantissa << (real.is_decimal ? 'e' : 'p') << real.exponent; + } + + auto FormatArg(SemanticsStringId id) -> void { + out_ << '"'; + out_.write_escaped(semantics_ir_.GetString(id), /*UseHexEscapes=*/true); + out_ << '"'; + } + + auto FormatArg(SemanticsTypeId id) -> void { FormatType(id); } + + auto FormatArg(SemanticsTypeBlockId id) -> void { + out_ << '('; + llvm::ListSeparator sep; + for (auto type_id : semantics_ir_.GetTypeBlock(id)) { + out_ << sep; + FormatArg(type_id); + } + out_ << ')'; + } + + auto FormatNodeName(SemanticsNodeId id) -> void { + out_ << node_namer_.GetNameFor(scope_, id); + } + + auto FormatLabel(SemanticsNodeBlockId id) -> void { + out_ << node_namer_.GetLabelFor(scope_, id); + } + + auto FormatString(SemanticsStringId id) -> void { + out_ << semantics_ir_.GetString(id); + } + + auto FormatFunctionName(SemanticsFunctionId id) -> void { + out_ << node_namer_.GetNameFor(id); + } + + auto FormatType(SemanticsTypeId id) -> void { + if (!id.is_valid()) { + out_ << "invalid"; + } else { + out_ << semantics_ir_.StringifyType(id, /*in_type_context=*/true); + } + } + + private: + const SemanticsIR& semantics_ir_; + llvm::raw_ostream& out_; + NodeNamer node_namer_; + NodeNamer::ScopeIndex scope_ = NodeNamer::ScopeIndex::None; + bool in_terminator_sequence = false; +}; + +auto FormatSemanticsIR(const TokenizedBuffer& tokenized_buffer, + const ParseTree& parse_tree, + const SemanticsIR& semantics_ir, llvm::raw_ostream& out) + -> void { + SemanticsIRFormatter(tokenized_buffer, parse_tree, semantics_ir, out) + .Format(); +} + +} // namespace Carbon diff --git a/toolchain/semantics/semantics_ir_formatter.h b/toolchain/semantics/semantics_ir_formatter.h new file mode 100644 index 0000000000000..6a0ea35818e13 --- /dev/null +++ b/toolchain/semantics/semantics_ir_formatter.h @@ -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 + +#ifndef CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_FORMATTER_H_ +#define CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_FORMATTER_H_ + +#include "llvm/Support/raw_ostream.h" +#include "toolchain/semantics/semantics_ir.h" + +namespace Carbon { + +auto FormatSemanticsIR(const TokenizedBuffer& tokenized_buffer, + const ParseTree& parse_tree, + const SemanticsIR& semantics_ir, llvm::raw_ostream& out) + -> void; + +} // namespace Carbon + +#endif // CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_FORMATTER_H_ diff --git a/toolchain/semantics/semantics_ir_test.cpp b/toolchain/semantics/semantics_ir_test.cpp index e2233396e51a5..e8ee468a98884 100644 --- a/toolchain/semantics/semantics_ir_test.cpp +++ b/toolchain/semantics/semantics_ir_test.cpp @@ -32,7 +32,7 @@ TEST(SemanticsIRTest, YAML) { llvm::MemoryBuffer::getMemBuffer("var x: i32 = 0;"))); TestRawOstream print_stream; Driver d(fs, print_stream, llvm::errs()); - d.RunFullCommand({"dump", "semantics-ir", "test.carbon"}); + d.RunFullCommand({"dump", "raw-semantics-ir", "test.carbon"}); // Matches the ID of a node. The numbers may change because of builtin // cross-references, so this code is only doing loose structural checks. diff --git a/toolchain/semantics/semantics_node_kind.cpp b/toolchain/semantics/semantics_node_kind.cpp index 06b4dc115446e..0d287d4155d82 100644 --- a/toolchain/semantics/semantics_node_kind.cpp +++ b/toolchain/semantics/semantics_node_kind.cpp @@ -11,9 +11,26 @@ CARBON_DEFINE_ENUM_CLASS_NAMES(SemanticsNodeKind) = { #include "toolchain/semantics/semantics_node_kind.def" }; +// Returns the name to use for this node kind in Semantics IR. +[[nodiscard]] auto SemanticsNodeKind::ir_name() const -> llvm::StringRef { + static constexpr llvm::StringRef Table[] = { +#define CARBON_SEMANTICS_NODE_KIND_WITH_IR_NAME(Name, IR_Name) IR_Name, +#include "toolchain/semantics/semantics_node_kind.def" + }; + return Table[AsInt()]; +} + +auto SemanticsNodeKind::value_kind() const -> SemanticsNodeValueKind { + static constexpr SemanticsNodeValueKind Table[] = { +#define CARBON_SEMANTICS_NODE_KIND_WITH_VALUE_KIND(Name, ValueKind) \ + SemanticsNodeValueKind::ValueKind, +#include "toolchain/semantics/semantics_node_kind.def" + }; + return Table[AsInt()]; +} + auto SemanticsNodeKind::terminator_kind() const -> SemanticsTerminatorKind { static constexpr SemanticsTerminatorKind Table[] = { -#define CARBON_SEMANTICS_NODE_KIND(Name) SemanticsTerminatorKind::NotTerminator, #define CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Name, TerminatorKind) \ SemanticsTerminatorKind::TerminatorKind, #include "toolchain/semantics/semantics_node_kind.def" diff --git a/toolchain/semantics/semantics_node_kind.def b/toolchain/semantics/semantics_node_kind.def index c1a33457b6f47..bd1d0294e25b0 100644 --- a/toolchain/semantics/semantics_node_kind.def +++ b/toolchain/semantics/semantics_node_kind.def @@ -7,57 +7,86 @@ // inclusion to expand to the desired output. Macro definitions are cleaned up // at the end of this file. // -// Supported x-macros are: +// Exactly one of these macros should be defined before including this header: // - CARBON_SEMANTICS_NODE_KIND(Name) -// Defines a node kind. +// Invoked for each kind of semantic node. +// - CARBON_SEMANTICS_NODE_KIND_WITH_VALUE_KIND(Name, TypeFieldKind) +// Invoked for each kind of semantic node, along with information about +// whether the node produces a value, and if so, what kind of value. // - CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Name, TerminatorKind) -// Defines a node kind for a terminator node. +// Invoked for each kind of semantic node, along with information about +// whether the node is a terminator node. +// - CARBON_SEMANTICS_NODE_KIND_WITH_IR_NAME(Name, IRName) +// Invoked for each kind of semantic node, along with the name that is used +// to denote this node in textual Semantics IR. -#ifndef CARBON_SEMANTICS_NODE_KIND -#error "Must define the x-macro to use this file." -#endif - -#ifndef CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND -#define CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Name, TerminatorKind) \ +#if defined(CARBON_SEMANTICS_NODE_KIND) +#define CARBON_SEMANTICS_NODE_KIND_IMPL(Name, IRName, ValueKind, \ + TerminatorKind) \ CARBON_SEMANTICS_NODE_KIND(Name) +#elif defined(CARBON_SEMANTICS_NODE_KIND_WITH_VALUE_KIND) +#define CARBON_SEMANTICS_NODE_KIND_IMPL(Name, IRName, ValueKind, \ + TerminatorKind) \ + CARBON_SEMANTICS_NODE_KIND_WITH_VALUE_KIND(Name, ValueKind) +#elif defined(CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND) +#define CARBON_SEMANTICS_NODE_KIND_IMPL(Name, IRName, ValueKind, \ + TerminatorKind) \ + CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Name, TerminatorKind) +#elif defined(CARBON_SEMANTICS_NODE_KIND_WITH_IR_NAME) +#define CARBON_SEMANTICS_NODE_KIND_IMPL(Name, IRName, ValueKind, \ + TerminatorKind) \ + CARBON_SEMANTICS_NODE_KIND_WITH_IR_NAME(Name, IRName) +#else +#error "Must define the x-macro to use this file." #endif -CARBON_SEMANTICS_NODE_KIND(Invalid) +CARBON_SEMANTICS_NODE_KIND_IMPL(Invalid, "invalid", None, NotTerminator) // A cross-reference between IRs. -CARBON_SEMANTICS_NODE_KIND(CrossReference) +CARBON_SEMANTICS_NODE_KIND_IMPL(CrossReference, "xref", Typed, NotTerminator) -CARBON_SEMANTICS_NODE_KIND(AddressOf) -CARBON_SEMANTICS_NODE_KIND(Assign) -CARBON_SEMANTICS_NODE_KIND(BinaryOperatorAdd) -CARBON_SEMANTICS_NODE_KIND(BindName) -CARBON_SEMANTICS_NODE_KIND(BlockArg) -CARBON_SEMANTICS_NODE_KIND(BoolLiteral) -CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Branch, Terminator) -CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(BranchIf, TerminatorSequence) -CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(BranchWithArg, Terminator) -CARBON_SEMANTICS_NODE_KIND(Builtin) -CARBON_SEMANTICS_NODE_KIND(Call) -CARBON_SEMANTICS_NODE_KIND(ConstType) -CARBON_SEMANTICS_NODE_KIND(Dereference) -CARBON_SEMANTICS_NODE_KIND(FunctionDeclaration) -CARBON_SEMANTICS_NODE_KIND(Index) -CARBON_SEMANTICS_NODE_KIND(IntegerLiteral) -CARBON_SEMANTICS_NODE_KIND(Namespace) -CARBON_SEMANTICS_NODE_KIND(PointerType) -CARBON_SEMANTICS_NODE_KIND(RealLiteral) -CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Return, Terminator) -CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(ReturnExpression, Terminator) -CARBON_SEMANTICS_NODE_KIND(StringLiteral) -CARBON_SEMANTICS_NODE_KIND(StructMemberAccess) -CARBON_SEMANTICS_NODE_KIND(StructType) -CARBON_SEMANTICS_NODE_KIND(StructTypeField) -CARBON_SEMANTICS_NODE_KIND(StructValue) -CARBON_SEMANTICS_NODE_KIND(StubReference) -CARBON_SEMANTICS_NODE_KIND(TupleType) -CARBON_SEMANTICS_NODE_KIND(TupleValue) -CARBON_SEMANTICS_NODE_KIND(UnaryOperatorNot) -CARBON_SEMANTICS_NODE_KIND(VarStorage) +CARBON_SEMANTICS_NODE_KIND_IMPL(AddressOf, "address_of", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Assign, "assign", None, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(BinaryOperatorAdd, "add", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(BindName, "bind_name", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(BlockArg, "block_arg", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(BoolLiteral, "bool_value", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Branch, "br", None, Terminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(BranchIf, "br", None, TerminatorSequence) +CARBON_SEMANTICS_NODE_KIND_IMPL(BranchWithArg, "br", None, Terminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Builtin, "builtin", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Call, "call", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(ConstType, "const_type", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Dereference, "dereference", Typed, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(FunctionDeclaration, "fn_decl", Untyped, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Index, "tuple_index", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(IntegerLiteral, "int_value", Typed, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Namespace, "namespace", Untyped, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(PointerType, "ptr_type", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(RealLiteral, "real_value", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(Return, "return", None, Terminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(ReturnExpression, "return", None, Terminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(StringLiteral, "string_value", Typed, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(StructMemberAccess, "struct_access", Typed, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(StructType, "struct_type", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(StructTypeField, "struct_type_field", None, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(StructValue, "struct_value", Typed, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(StubReference, "stub_reference", Typed, + NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(TupleType, "tuple_type", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(TupleValue, "tuple_value", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(UnaryOperatorNot, "not", Typed, NotTerminator) +CARBON_SEMANTICS_NODE_KIND_IMPL(VarStorage, "var", Typed, NotTerminator) -#undef CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND #undef CARBON_SEMANTICS_NODE_KIND +#undef CARBON_SEMANTICS_NODE_KIND_WITH_VALUE_KIND +#undef CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND +#undef CARBON_SEMANTICS_NODE_KIND_WITH_IR_NAME +#undef CARBON_SEMANTICS_NODE_KIND_IMPL diff --git a/toolchain/semantics/semantics_node_kind.h b/toolchain/semantics/semantics_node_kind.h index 7ae40df2fc1c9..8272dcbe6d8cc 100644 --- a/toolchain/semantics/semantics_node_kind.h +++ b/toolchain/semantics/semantics_node_kind.h @@ -17,6 +17,19 @@ CARBON_DEFINE_RAW_ENUM_CLASS(SemanticsNodeKind, uint8_t) { #include "toolchain/semantics/semantics_node_kind.def" }; +// Whether a node produces or represents a value, and if so, what kind of value. +enum class SemanticsNodeValueKind { + // This node doesn't produce a value, and shouldn't be referenced by other + // nodes. + None, + // This node represents an untyped value. It may be referenced by other nodes + // expecting this kind of value. + Untyped, + // This node represents an expression or expression-like construct that + // produces a value of the type indicated by its `type_id` field. + Typed, +}; + // Whether a node is a terminator or part of the terminator sequence. The nodes // in a block appear in the order NotTerminator, then TerminatorSequence, then // Terminator, which is also the numerical order of these values. @@ -37,6 +50,12 @@ class SemanticsNodeKind : public CARBON_ENUM_BASE(SemanticsNodeKind) { using EnumBase::Create; + // Returns the name to use for this node kind in Semantics IR. + [[nodiscard]] auto ir_name() const -> llvm::StringRef; + + // Returns whether this kind of node is expected to produce a value. + [[nodiscard]] auto value_kind() const -> SemanticsNodeValueKind; + // Returns whether this node kind is a code block terminator, such as an // unconditional branch instruction, or part of the termination sequence, // such as a conditional branch instruction. The termination sequence of a diff --git a/toolchain/semantics/testdata/basics/builtin_nodes.carbon b/toolchain/semantics/testdata/basics/builtin_nodes.carbon index d94cde5cc8a4d..52c7a6e370bde 100644 --- a/toolchain/semantics/testdata/basics/builtin_nodes.carbon +++ b/toolchain/semantics/testdata/basics/builtin_nodes.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: dump semantics-ir --include_builtins %s +// ARGS: dump raw-semantics-ir --include_builtins %s // // AUTOUPDATE diff --git a/toolchain/semantics/testdata/basics/builtin_types.carbon b/toolchain/semantics/testdata/basics/builtin_types.carbon index c61050b69b196..df3a4b1650bc5 100644 --- a/toolchain/semantics/testdata/basics/builtin_types.carbon +++ b/toolchain/semantics/testdata/basics/builtin_types.carbon @@ -70,3 +70,17 @@ var test_type: type = i32; // CHECK:STDOUT: node+14, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %test_i32: i32 = var +// CHECK:STDOUT: %.loc7: i32 = int_value 0 +// CHECK:STDOUT: assign %test_i32, %.loc7 +// CHECK:STDOUT: %test_f64: f64 = var +// CHECK:STDOUT: %.loc8: f64 = real_value 1e-1 +// CHECK:STDOUT: assign %test_f64, %.loc8 +// CHECK:STDOUT: %test_str: String = var +// CHECK:STDOUT: %.loc9: String = string_value "Test" +// CHECK:STDOUT: assign %test_str, %.loc9 +// CHECK:STDOUT: %test_type: type = var +// CHECK:STDOUT: assign %test_type, i32 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/empty.carbon b/toolchain/semantics/testdata/basics/empty.carbon index e3eb06ce7d5e2..df0283c0f0789 100644 --- a/toolchain/semantics/testdata/basics/empty.carbon +++ b/toolchain/semantics/testdata/basics/empty.carbon @@ -23,3 +23,6 @@ // CHECK:STDOUT: [ // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/empty_decl.carbon b/toolchain/semantics/testdata/basics/empty_decl.carbon index b707dad3a1c82..6890c81472cf7 100644 --- a/toolchain/semantics/testdata/basics/empty_decl.carbon +++ b/toolchain/semantics/testdata/basics/empty_decl.carbon @@ -25,3 +25,6 @@ // CHECK:STDOUT: [ // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/fail_name_lookup.carbon b/toolchain/semantics/testdata/basics/fail_name_lookup.carbon index 6504f2ff5ba54..e5cb40f767029 100644 --- a/toolchain/semantics/testdata/basics/fail_name_lookup.carbon +++ b/toolchain/semantics/testdata/basics/fail_name_lookup.carbon @@ -41,3 +41,12 @@ fn Main() { // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/fail_non_type_as_type.carbon b/toolchain/semantics/testdata/basics/fail_non_type_as_type.carbon index 8ca495c0d96a5..8a9dd9c6d5dd8 100644 --- a/toolchain/semantics/testdata/basics/fail_non_type_as_type.carbon +++ b/toolchain/semantics/testdata/basics/fail_non_type_as_type.carbon @@ -41,3 +41,9 @@ var x: type = 42; // CHECK:STDOUT: node+3, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %x: type = var +// CHECK:STDOUT: %.loc10: i32 = int_value 42 +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/fail_qualifier_unsupported.carbon b/toolchain/semantics/testdata/basics/fail_qualifier_unsupported.carbon index ce524aebe9523..781ad17a96160 100644 --- a/toolchain/semantics/testdata/basics/fail_qualifier_unsupported.carbon +++ b/toolchain/semantics/testdata/basics/fail_qualifier_unsupported.carbon @@ -45,3 +45,9 @@ var y: i32 = x.b; // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %y: i32 = var +// CHECK:STDOUT: assign %y, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/parens.carbon b/toolchain/semantics/testdata/basics/parens.carbon index 4f69e1fcd7395..c79a037de837f 100644 --- a/toolchain/semantics/testdata/basics/parens.carbon +++ b/toolchain/semantics/testdata/basics/parens.carbon @@ -43,3 +43,11 @@ var test_i32: i32 = ((1) + (2)); // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %test_i32: i32 = var +// CHECK:STDOUT: %.loc7_23: i32 = int_value 1 +// CHECK:STDOUT: %.loc7_29: i32 = int_value 2 +// CHECK:STDOUT: %.loc7_26: i32 = add %.loc7_23, %.loc7_29 +// CHECK:STDOUT: assign %test_i32, %.loc7_26 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/textual_ir.carbon b/toolchain/semantics/testdata/basics/textual_ir.carbon new file mode 100644 index 0000000000000..75376b6bacdfe --- /dev/null +++ b/toolchain/semantics/testdata/basics/textual_ir.carbon @@ -0,0 +1,21 @@ +// 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 +// +// ARGS: dump semantics-ir %s +// +// Just check that the raw IR format isn't included in `dump semantics-ir` mode. +// AUTOUPDATE + +fn Foo() { + return; +} + +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10 = fn_decl @Foo +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/basics/verbose.carbon b/toolchain/semantics/testdata/basics/verbose.carbon index eabd1d2df7d29..0439be9731506 100644 --- a/toolchain/semantics/testdata/basics/verbose.carbon +++ b/toolchain/semantics/testdata/basics/verbose.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: -v dump semantics-ir %s +// ARGS: -v dump raw-semantics-ir %s // // Only checks a couple statements in order to minimize manual update churn. // NOAUTOUPDATE diff --git a/toolchain/semantics/testdata/const/collapse.carbon b/toolchain/semantics/testdata/const/collapse.carbon index fa785f9e67dcc..7df8e3619694b 100644 --- a/toolchain/semantics/testdata/const/collapse.carbon +++ b/toolchain/semantics/testdata/const/collapse.carbon @@ -69,3 +69,16 @@ fn F(p: const i32**) -> const (const i32)** { // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc11_32: type = const_type i32 +// CHECK:STDOUT: %.loc11_25: type = const_type const i32 +// CHECK:STDOUT: %.loc11_42: type = ptr_type const i32 +// CHECK:STDOUT: %.loc11_43: type = ptr_type const i32* +// CHECK:STDOUT: %.loc11_1 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(%p: const i32**) -> const i32** { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return %p +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/const/fail_collapse.carbon b/toolchain/semantics/testdata/const/fail_collapse.carbon index f9c7316190bd4..ef1b627b542a9 100644 --- a/toolchain/semantics/testdata/const/fail_collapse.carbon +++ b/toolchain/semantics/testdata/const/fail_collapse.carbon @@ -71,3 +71,14 @@ fn G(p: const (const i32)**) -> i32** { // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_36: type = ptr_type i32 +// CHECK:STDOUT: %.loc10_37: type = ptr_type i32* +// CHECK:STDOUT: %.loc10_1 = fn_decl @G +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G(%p: const i32**) -> i32** { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/empty_struct.carbon b/toolchain/semantics/testdata/function/call/empty_struct.carbon index 52d999aa77fd9..6533c2ce21cc0 100644 --- a/toolchain/semantics/testdata/function/call/empty_struct.carbon +++ b/toolchain/semantics/testdata/function/call/empty_struct.carbon @@ -75,3 +75,22 @@ fn Main() { // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_20: {} = struct_value () +// CHECK:STDOUT: %.loc7_1 = fn_decl @Echo +// CHECK:STDOUT: %.loc11 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Echo(%a: {}) -> {} { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return %a +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc12_9.1: {} = struct_value () +// CHECK:STDOUT: %.loc12_9.2: {} = stub_reference %.loc12_9.1 +// CHECK:STDOUT: %.loc12_7: {} = call @Echo(%.loc12_9.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/empty_tuple.carbon b/toolchain/semantics/testdata/function/call/empty_tuple.carbon index 5412a41b66f3c..166590da46e5a 100644 --- a/toolchain/semantics/testdata/function/call/empty_tuple.carbon +++ b/toolchain/semantics/testdata/function/call/empty_tuple.carbon @@ -77,3 +77,22 @@ fn Main() { // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_20: () = tuple_value () +// CHECK:STDOUT: %.loc7_1 = fn_decl @Echo +// CHECK:STDOUT: %.loc11 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Echo(%a: ()) -> () { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return %a +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc12_9.1: () = tuple_value () +// CHECK:STDOUT: %.loc12_9.2: () = stub_reference %.loc12_9.1 +// CHECK:STDOUT: %.loc12_7: () = call @Echo(%.loc12_9.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/fail_param_count.carbon b/toolchain/semantics/testdata/function/call/fail_param_count.carbon index 813ba65859a43..b6d5bdb684b6d 100644 --- a/toolchain/semantics/testdata/function/call/fail_param_count.carbon +++ b/toolchain/semantics/testdata/function/call/fail_param_count.carbon @@ -178,3 +178,42 @@ fn Main() { // CHECK:STDOUT: node+24, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Run0 +// CHECK:STDOUT: %.loc8 = fn_decl @Run1 +// CHECK:STDOUT: %.loc9 = fn_decl @Run2 +// CHECK:STDOUT: %.loc11 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Run0() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Run1(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Run2(%a: i32, %b: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc18_8.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc18_8.2: i32 = stub_reference %.loc18_8.1 +// CHECK:STDOUT: %.loc25_8.1: i32 = int_value 0 +// CHECK:STDOUT: %.loc25_8.2: i32 = stub_reference %.loc25_8.1 +// CHECK:STDOUT: %.loc25_11.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc25_11.2: i32 = stub_reference %.loc25_11.1 +// CHECK:STDOUT: %.loc40_8.1: i32 = int_value 0 +// CHECK:STDOUT: %.loc40_8.2: i32 = stub_reference %.loc40_8.1 +// CHECK:STDOUT: %.loc40_11.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc40_11.2: i32 = stub_reference %.loc40_11.1 +// CHECK:STDOUT: %.loc55_8.1: i32 = int_value 0 +// CHECK:STDOUT: %.loc55_8.2: i32 = stub_reference %.loc55_8.1 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/fail_param_type.carbon b/toolchain/semantics/testdata/function/call/fail_param_type.carbon index 11637fac5b650..fa6ec6b762122 100644 --- a/toolchain/semantics/testdata/function/call/fail_param_type.carbon +++ b/toolchain/semantics/testdata/function/call/fail_param_type.carbon @@ -73,3 +73,20 @@ fn Main() { // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Run +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Run(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc16_7.1: f64 = real_value 10e-1 +// CHECK:STDOUT: %.loc16_7.2: f64 = stub_reference %.loc16_7.1 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/fail_return_type_mismatch.carbon b/toolchain/semantics/testdata/function/call/fail_return_type_mismatch.carbon index 14098ec84cf80..f4ef4a1cdce79 100644 --- a/toolchain/semantics/testdata/function/call/fail_return_type_mismatch.carbon +++ b/toolchain/semantics/testdata/function/call/fail_return_type_mismatch.carbon @@ -64,3 +64,22 @@ fn Run() { // CHECK:STDOUT: node+8, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc9 = fn_decl @Run +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo() -> f64 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc7: f64 = real_value 10e-1 +// CHECK:STDOUT: return %.loc7 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Run() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %.loc13: f64 = call @Foo() +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/i32.carbon b/toolchain/semantics/testdata/function/call/i32.carbon index 9e5cb9bda486c..23e652e3d81b5 100644 --- a/toolchain/semantics/testdata/function/call/i32.carbon +++ b/toolchain/semantics/testdata/function/call/i32.carbon @@ -77,3 +77,23 @@ fn Main() { // CHECK:STDOUT: node+8, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Echo +// CHECK:STDOUT: %.loc11 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Echo(%a: i32) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return %a +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %b: i32 = var +// CHECK:STDOUT: %.loc12_21.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc12_21.2: i32 = stub_reference %.loc12_21.1 +// CHECK:STDOUT: %.loc12_20: i32 = call @Echo(%.loc12_21.2) +// CHECK:STDOUT: assign %b, %.loc12_20 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/more_param_ir.carbon b/toolchain/semantics/testdata/function/call/more_param_ir.carbon index e59a548faedea..a0094ed467b94 100644 --- a/toolchain/semantics/testdata/function/call/more_param_ir.carbon +++ b/toolchain/semantics/testdata/function/call/more_param_ir.carbon @@ -113,3 +113,32 @@ fn Main() { // CHECK:STDOUT: node+20, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32, %b: i32, %c: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_7: i32 = int_value 1 +// CHECK:STDOUT: %.loc11_11: i32 = int_value 2 +// CHECK:STDOUT: %.loc11_9: i32 = add %.loc11_7, %.loc11_11 +// CHECK:STDOUT: %.loc11_15: i32 = int_value 3 +// CHECK:STDOUT: %.loc11_13.1: i32 = add %.loc11_9, %.loc11_15 +// CHECK:STDOUT: %.loc11_13.2: i32 = stub_reference %.loc11_13.1 +// CHECK:STDOUT: %.loc11_18: i32 = int_value 4 +// CHECK:STDOUT: %.loc11_22: i32 = int_value 5 +// CHECK:STDOUT: %.loc11_20.1: i32 = add %.loc11_18, %.loc11_22 +// CHECK:STDOUT: %.loc11_20.2: i32 = stub_reference %.loc11_20.1 +// CHECK:STDOUT: %.loc11_25.1: i32 = int_value 6 +// CHECK:STDOUT: %.loc11_25.2: i32 = stub_reference %.loc11_25.1 +// CHECK:STDOUT: %.loc11_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc11_6.2: () = call @Foo(%.loc11_13.2, %.loc11_20.2, %.loc11_25.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/params_one.carbon b/toolchain/semantics/testdata/function/call/params_one.carbon index b9bb6f7174461..13b1a18c0a73c 100644 --- a/toolchain/semantics/testdata/function/call/params_one.carbon +++ b/toolchain/semantics/testdata/function/call/params_one.carbon @@ -73,3 +73,22 @@ fn Main() { // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc10_7.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_7.2: i32 = stub_reference %.loc10_7.1 +// CHECK:STDOUT: %.loc10_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc10_6.2: () = call @Foo(%.loc10_7.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/params_one_comma.carbon b/toolchain/semantics/testdata/function/call/params_one_comma.carbon index cf2dbde85699d..596041714848e 100644 --- a/toolchain/semantics/testdata/function/call/params_one_comma.carbon +++ b/toolchain/semantics/testdata/function/call/params_one_comma.carbon @@ -84,3 +84,25 @@ fn Main() { // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc10_7.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_7.2: i32 = stub_reference %.loc10_7.1 +// CHECK:STDOUT: %.loc10_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc10_6.2: () = call @Foo(%.loc10_7.2) +// CHECK:STDOUT: %.loc11_7.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc11_7.2: i32 = stub_reference %.loc11_7.1 +// CHECK:STDOUT: %.loc11_6: () = call @Foo(%.loc11_7.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/params_two.carbon b/toolchain/semantics/testdata/function/call/params_two.carbon index 05bbfdf515c1b..1cd9f0b549b7d 100644 --- a/toolchain/semantics/testdata/function/call/params_two.carbon +++ b/toolchain/semantics/testdata/function/call/params_two.carbon @@ -85,3 +85,24 @@ fn Main() { // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32, %b: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc10_7.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_7.2: i32 = stub_reference %.loc10_7.1 +// CHECK:STDOUT: %.loc10_10.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc10_10.2: i32 = stub_reference %.loc10_10.1 +// CHECK:STDOUT: %.loc10_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc10_6.2: () = call @Foo(%.loc10_7.2, %.loc10_10.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/params_two_comma.carbon b/toolchain/semantics/testdata/function/call/params_two_comma.carbon index fb1957e2fd706..0dd54e5005dc5 100644 --- a/toolchain/semantics/testdata/function/call/params_two_comma.carbon +++ b/toolchain/semantics/testdata/function/call/params_two_comma.carbon @@ -102,3 +102,29 @@ fn Main() { // CHECK:STDOUT: node+16, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32, %b: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc10_7.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_7.2: i32 = stub_reference %.loc10_7.1 +// CHECK:STDOUT: %.loc10_10.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc10_10.2: i32 = stub_reference %.loc10_10.1 +// CHECK:STDOUT: %.loc10_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc10_6.2: () = call @Foo(%.loc10_7.2, %.loc10_10.2) +// CHECK:STDOUT: %.loc11_7.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc11_7.2: i32 = stub_reference %.loc11_7.1 +// CHECK:STDOUT: %.loc11_10.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc11_10.2: i32 = stub_reference %.loc11_10.1 +// CHECK:STDOUT: %.loc11_6: () = call @Foo(%.loc11_7.2, %.loc11_10.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/params_zero.carbon b/toolchain/semantics/testdata/function/call/params_zero.carbon index f890b8cc29356..d0f487a3ed375 100644 --- a/toolchain/semantics/testdata/function/call/params_zero.carbon +++ b/toolchain/semantics/testdata/function/call/params_zero.carbon @@ -54,3 +54,20 @@ fn Main() { // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc10_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc10_6.2: () = call @Foo() +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/call/return_implicit.carbon b/toolchain/semantics/testdata/function/call/return_implicit.carbon index b70d7a344ab8a..46c8f4c53af8a 100644 --- a/toolchain/semantics/testdata/function/call/return_implicit.carbon +++ b/toolchain/semantics/testdata/function/call/return_implicit.carbon @@ -64,3 +64,23 @@ fn Main() { // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @MakeImplicitEmptyTuple +// CHECK:STDOUT: %.loc10 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @MakeImplicitEmptyTuple() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_11.1: type = tuple_type () +// CHECK:STDOUT: %.loc11_11.2: () = tuple_value () +// CHECK:STDOUT: %b: () = var +// CHECK:STDOUT: %.loc11_37: () = call @MakeImplicitEmptyTuple() +// CHECK:STDOUT: assign %b, %.loc11_37 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/declaration/simple.carbon b/toolchain/semantics/testdata/function/declaration/simple.carbon index cadf16a4e19db..49f83992d85e5 100644 --- a/toolchain/semantics/testdata/function/declaration/simple.carbon +++ b/toolchain/semantics/testdata/function/declaration/simple.carbon @@ -48,3 +48,17 @@ fn G() { F(); } // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: %.loc9 = fn_decl @G +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(); +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc9_11.1: type = tuple_type () +// CHECK:STDOUT: %.loc9_11.2: () = call @F() +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/fail_param_name_conflict.carbon b/toolchain/semantics/testdata/function/definition/fail_param_name_conflict.carbon index 1d9b9b293d3cf..10564800d4f0e 100644 --- a/toolchain/semantics/testdata/function/definition/fail_param_name_conflict.carbon +++ b/toolchain/semantics/testdata/function/definition/fail_param_name_conflict.carbon @@ -57,3 +57,12 @@ fn Bar(a: i32, a: i32) {} // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc13 = fn_decl @Bar +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Bar(%a.loc13_8: i32, %a.loc13_16: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/order.carbon b/toolchain/semantics/testdata/function/definition/order.carbon index 89867c8cf0de4..c25d83e6b858f 100644 --- a/toolchain/semantics/testdata/function/definition/order.carbon +++ b/toolchain/semantics/testdata/function/definition/order.carbon @@ -53,3 +53,24 @@ fn Baz() {} // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc8 = fn_decl @Bar +// CHECK:STDOUT: %.loc9 = fn_decl @Baz +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Bar() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Baz() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/params_one.carbon b/toolchain/semantics/testdata/function/definition/params_one.carbon index 1e17800746428..aeb7f565c89cf 100644 --- a/toolchain/semantics/testdata/function/definition/params_one.carbon +++ b/toolchain/semantics/testdata/function/definition/params_one.carbon @@ -46,3 +46,12 @@ fn Foo(a: i32) {} // CHECK:STDOUT: node+3, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/params_one_comma.carbon b/toolchain/semantics/testdata/function/definition/params_one_comma.carbon index 24e120530e5d0..16112373c0f61 100644 --- a/toolchain/semantics/testdata/function/definition/params_one_comma.carbon +++ b/toolchain/semantics/testdata/function/definition/params_one_comma.carbon @@ -46,3 +46,12 @@ fn Foo(a: i32,) {} // CHECK:STDOUT: node+3, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/params_two.carbon b/toolchain/semantics/testdata/function/definition/params_two.carbon index 25d27c0551efe..79fe959089bac 100644 --- a/toolchain/semantics/testdata/function/definition/params_two.carbon +++ b/toolchain/semantics/testdata/function/definition/params_two.carbon @@ -52,3 +52,12 @@ fn Foo(a: i32, b: i32) {} // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32, %b: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/params_two_comma.carbon b/toolchain/semantics/testdata/function/definition/params_two_comma.carbon index 7123cbce546d7..0f9dd11865c51 100644 --- a/toolchain/semantics/testdata/function/definition/params_two_comma.carbon +++ b/toolchain/semantics/testdata/function/definition/params_two_comma.carbon @@ -52,3 +52,12 @@ fn Foo(a: i32, b: i32,) {} // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32, %b: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/params_zero.carbon b/toolchain/semantics/testdata/function/definition/params_zero.carbon index ea3a0eca4ecbf..dc8d12d7a304b 100644 --- a/toolchain/semantics/testdata/function/definition/params_zero.carbon +++ b/toolchain/semantics/testdata/function/definition/params_zero.carbon @@ -35,3 +35,12 @@ fn Foo() {} // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/definition/same_param_name.carbon b/toolchain/semantics/testdata/function/definition/same_param_name.carbon index d6e16048f8f1c..d71c24d8c3746 100644 --- a/toolchain/semantics/testdata/function/definition/same_param_name.carbon +++ b/toolchain/semantics/testdata/function/definition/same_param_name.carbon @@ -64,3 +64,18 @@ fn Bar(a: i32) {} // CHECK:STDOUT: node+7, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Foo +// CHECK:STDOUT: %.loc8 = fn_decl @Bar +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Foo(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Bar(%a: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if/else.carbon b/toolchain/semantics/testdata/if/else.carbon index 831de095694ac..8a8d5627ba130 100644 --- a/toolchain/semantics/testdata/if/else.carbon +++ b/toolchain/semantics/testdata/if/else.carbon @@ -106,3 +106,43 @@ fn If(b: bool) { // CHECK:STDOUT: node+17, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: %.loc8 = fn_decl @G +// CHECK:STDOUT: %.loc9 = fn_decl @H +// CHECK:STDOUT: %.loc11 = fn_decl @If +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @H() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @If(%b: bool) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc13 else br !.loc15 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc13: +// CHECK:STDOUT: %.loc13_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc13_6.2: () = call @F() +// CHECK:STDOUT: br !.loc17 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc15: +// CHECK:STDOUT: %.loc15: () = call @G() +// CHECK:STDOUT: br !.loc17 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc17: +// CHECK:STDOUT: %.loc17: () = call @H() +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if/fail_reachable_fallthrough.carbon b/toolchain/semantics/testdata/if/fail_reachable_fallthrough.carbon index 8adcd11e2af08..77fdfb2741788 100644 --- a/toolchain/semantics/testdata/if/fail_reachable_fallthrough.carbon +++ b/toolchain/semantics/testdata/if/fail_reachable_fallthrough.carbon @@ -150,3 +150,48 @@ fn If3(b: bool) -> i32 { // CHECK:STDOUT: [ // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @If1 +// CHECK:STDOUT: %.loc17 = fn_decl @If2 +// CHECK:STDOUT: %.loc27 = fn_decl @If3 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @If1(%b: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc9 else br !.loc8 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc9: +// CHECK:STDOUT: %.loc9: i32 = int_value 1 +// CHECK:STDOUT: return %.loc9 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8: +// CHECK:STDOUT: br !.1 +// CHECK:STDOUT: +// CHECK:STDOUT: !.1: +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @If2(%b: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc18 else br !.loc20 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc18: +// CHECK:STDOUT: br !.1 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc20: +// CHECK:STDOUT: %.loc20: i32 = int_value 2 +// CHECK:STDOUT: return %.loc20 +// CHECK:STDOUT: +// CHECK:STDOUT: !.1: +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @If3(%b: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc29 else br !.1 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc29: +// CHECK:STDOUT: %.loc29: i32 = int_value 1 +// CHECK:STDOUT: return %.loc29 +// CHECK:STDOUT: +// CHECK:STDOUT: !.1: +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if/fail_scope.carbon b/toolchain/semantics/testdata/if/fail_scope.carbon index 326645e9ced51..d7a594b2c1b18 100644 --- a/toolchain/semantics/testdata/if/fail_scope.carbon +++ b/toolchain/semantics/testdata/if/fail_scope.carbon @@ -77,3 +77,21 @@ fn VarScope(b: bool) -> i32 { // CHECK:STDOUT: node+11, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @VarScope +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @VarScope(%b: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc9 else br !.loc15 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc9: +// CHECK:STDOUT: %n: i32 = var +// CHECK:STDOUT: %.loc9: i32 = int_value 2 +// CHECK:STDOUT: assign %n, %.loc9 +// CHECK:STDOUT: return %n +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc15: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if/no_else.carbon b/toolchain/semantics/testdata/if/no_else.carbon index 4dc14a320e00d..3f17beebaadfd 100644 --- a/toolchain/semantics/testdata/if/no_else.carbon +++ b/toolchain/semantics/testdata/if/no_else.carbon @@ -89,3 +89,33 @@ fn If(b: bool) { // CHECK:STDOUT: node+13, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: %.loc8 = fn_decl @G +// CHECK:STDOUT: %.loc10 = fn_decl @If +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @If(%b: bool) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc12 else br !.loc14 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc12: +// CHECK:STDOUT: %.loc12_6.1: type = tuple_type () +// CHECK:STDOUT: %.loc12_6.2: () = call @F() +// CHECK:STDOUT: br !.loc14 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc14: +// CHECK:STDOUT: %.loc14: () = call @G() +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if/unreachable_fallthrough.carbon b/toolchain/semantics/testdata/if/unreachable_fallthrough.carbon index 78b7b03e83aa8..e88bbb2f0ef40 100644 --- a/toolchain/semantics/testdata/if/unreachable_fallthrough.carbon +++ b/toolchain/semantics/testdata/if/unreachable_fallthrough.carbon @@ -70,3 +70,20 @@ fn If(b: bool) -> i32 { // CHECK:STDOUT: node+8, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @If +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @If(%b: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc9 else br !.loc11 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc9: +// CHECK:STDOUT: %.loc9: i32 = int_value 1 +// CHECK:STDOUT: return %.loc9 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11: +// CHECK:STDOUT: %.loc11: i32 = int_value 2 +// CHECK:STDOUT: return %.loc11 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if_expression/basic.carbon b/toolchain/semantics/testdata/if_expression/basic.carbon index 439d04cf1cd3c..bef7a2f3ef894 100644 --- a/toolchain/semantics/testdata/if_expression/basic.carbon +++ b/toolchain/semantics/testdata/if_expression/basic.carbon @@ -81,3 +81,24 @@ fn F(b: bool, n: i32, m: i32) -> i32 { // CHECK:STDOUT: node+14, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(%b: bool, %n: i32, %m: i32) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc8_22 else br !.loc8_33 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_22: +// CHECK:STDOUT: %.loc8_22: i32 = add %n, %m +// CHECK:STDOUT: br !.loc8_10(%.loc8_22) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_33: +// CHECK:STDOUT: %.loc8_33: i32 = add %m, %n +// CHECK:STDOUT: br !.loc8_10(%.loc8_33) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_10: +// CHECK:STDOUT: %.loc8_10: i32 = block_arg !.loc8_10 +// CHECK:STDOUT: return %.loc8_10 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if_expression/constant_condition.carbon b/toolchain/semantics/testdata/if_expression/constant_condition.carbon index 55b230e5caa7e..ebcdcfec1f6e3 100644 --- a/toolchain/semantics/testdata/if_expression/constant_condition.carbon +++ b/toolchain/semantics/testdata/if_expression/constant_condition.carbon @@ -120,3 +120,58 @@ fn G() -> i32 { // CHECK:STDOUT: node+25, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @A +// CHECK:STDOUT: %.loc8 = fn_decl @B +// CHECK:STDOUT: %.loc10 = fn_decl @F +// CHECK:STDOUT: %.loc14 = fn_decl @G +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @A() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc7: i32 = int_value 1 +// CHECK:STDOUT: return %.loc7 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @B() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8: i32 = int_value 2 +// CHECK:STDOUT: return %.loc8 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_13: bool = bool_value true +// CHECK:STDOUT: if %.loc11_13 br !.loc11_24 else br !.loc11_33 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_24: +// CHECK:STDOUT: %.loc11_24: i32 = call @A() +// CHECK:STDOUT: br !.loc11_10(%.loc11_24) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_33: +// CHECK:STDOUT: %.loc11_33: i32 = call @B() +// CHECK:STDOUT: br !.loc11_10(%.loc11_33) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_10: +// CHECK:STDOUT: %.loc11_10: i32 = block_arg !.loc11_10 +// CHECK:STDOUT: return %.loc11_10 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc15_13: bool = bool_value false +// CHECK:STDOUT: if %.loc15_13 br !.loc15_25 else br !.loc15_34 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc15_25: +// CHECK:STDOUT: %.loc15_25: i32 = call @A() +// CHECK:STDOUT: br !.loc15_10(%.loc15_25) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc15_34: +// CHECK:STDOUT: %.loc15_34: i32 = call @B() +// CHECK:STDOUT: br !.loc15_10(%.loc15_34) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc15_10: +// CHECK:STDOUT: %.loc15_10: i32 = block_arg !.loc15_10 +// CHECK:STDOUT: return %.loc15_10 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if_expression/control_flow.carbon b/toolchain/semantics/testdata/if_expression/control_flow.carbon index 116a7fcce446f..b1e73412d38de 100644 --- a/toolchain/semantics/testdata/if_expression/control_flow.carbon +++ b/toolchain/semantics/testdata/if_expression/control_flow.carbon @@ -94,3 +94,38 @@ fn F(b: bool) -> i32 { // CHECK:STDOUT: node+16, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @A +// CHECK:STDOUT: %.loc8 = fn_decl @B +// CHECK:STDOUT: %.loc10 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @A() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc7: i32 = int_value 1 +// CHECK:STDOUT: return %.loc7 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @B() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8: i32 = int_value 2 +// CHECK:STDOUT: return %.loc8 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(%b: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %b br !.loc11_21 else br !.loc11_30 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_21: +// CHECK:STDOUT: %.loc11_21: i32 = call @A() +// CHECK:STDOUT: br !.loc11_10(%.loc11_21) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_30: +// CHECK:STDOUT: %.loc11_30: i32 = call @B() +// CHECK:STDOUT: br !.loc11_10(%.loc11_30) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_10: +// CHECK:STDOUT: %.loc11_10: i32 = block_arg !.loc11_10 +// CHECK:STDOUT: return %.loc11_10 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/if_expression/nested.carbon b/toolchain/semantics/testdata/if_expression/nested.carbon index 750d1cb0b28a7..87ca9994b7200 100644 --- a/toolchain/semantics/testdata/if_expression/nested.carbon +++ b/toolchain/semantics/testdata/if_expression/nested.carbon @@ -121,3 +121,46 @@ fn F(a: bool, b: bool, c: bool) -> i32 { // CHECK:STDOUT: node+26, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(%a: bool, %b: bool, %c: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: if %a br !.loc8_20.1 else br !.loc8_44.1 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_20.1: +// CHECK:STDOUT: if %b br !.loc8_30 else br !.loc8_37 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_30: +// CHECK:STDOUT: %.loc8_30: i32 = int_value 1 +// CHECK:STDOUT: br !.loc8_20.2(%.loc8_30) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_37: +// CHECK:STDOUT: %.loc8_37: i32 = int_value 2 +// CHECK:STDOUT: br !.loc8_20.2(%.loc8_37) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_20.2: +// CHECK:STDOUT: %.loc8_20: i32 = block_arg !.loc8_20.2 +// CHECK:STDOUT: br !.loc8_10(%.loc8_20) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_44.1: +// CHECK:STDOUT: if %c br !.loc8_54 else br !.loc8_61 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_54: +// CHECK:STDOUT: %.loc8_54: i32 = int_value 3 +// CHECK:STDOUT: br !.loc8_44.2(%.loc8_54) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_61: +// CHECK:STDOUT: %.loc8_61: i32 = int_value 4 +// CHECK:STDOUT: br !.loc8_44.2(%.loc8_61) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_44.2: +// CHECK:STDOUT: %.loc8_44: i32 = block_arg !.loc8_44.2 +// CHECK:STDOUT: br !.loc8_10(%.loc8_44) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc8_10: +// CHECK:STDOUT: %.loc8_10: i32 = block_arg !.loc8_10 +// CHECK:STDOUT: return %.loc8_10 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/element_access.carbon b/toolchain/semantics/testdata/index/element_access.carbon index c67b341250fbf..1920052024fcd 100644 --- a/toolchain/semantics/testdata/index/element_access.carbon +++ b/toolchain/semantics/testdata/index/element_access.carbon @@ -92,3 +92,23 @@ var c: i32 = b[0]; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_13.1: type = tuple_type (type) +// CHECK:STDOUT: %.loc7_13.2: (type,) = tuple_value (%.loc7_9) +// CHECK:STDOUT: %.loc7_13.3: type = tuple_type (i32) +// CHECK:STDOUT: %a: (i32,) = var +// CHECK:STDOUT: %.loc7_18.1: i32 = int_value 12 +// CHECK:STDOUT: %.loc7_18.2: i32 = stub_reference %.loc7_18.1 +// CHECK:STDOUT: %.loc7_21: (i32,) = tuple_value (%.loc7_18.2) +// CHECK:STDOUT: assign %a, %.loc7_21 +// CHECK:STDOUT: %.loc8_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_13: (type,) = tuple_value (%.loc8_9) +// CHECK:STDOUT: %b: (i32,) = var +// CHECK:STDOUT: assign %b, %a +// CHECK:STDOUT: %c: i32 = var +// CHECK:STDOUT: %.loc9_16: i32 = int_value 0 +// CHECK:STDOUT: %.loc9_17: i32 = tuple_index %b, %.loc9_16 +// CHECK:STDOUT: assign %c, %.loc9_17 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_empty_tuple_access.carbon b/toolchain/semantics/testdata/index/fail_empty_tuple_access.carbon index 6bcffb3eb0681..589c074865116 100644 --- a/toolchain/semantics/testdata/index/fail_empty_tuple_access.carbon +++ b/toolchain/semantics/testdata/index/fail_empty_tuple_access.carbon @@ -61,3 +61,21 @@ fn Run() { // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: %.loc9 = fn_decl @Run +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Run() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc13_4.1: type = tuple_type () +// CHECK:STDOUT: %.loc13_4.2: () = call @F() +// CHECK:STDOUT: %.loc13_7: i32 = int_value 0 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_large_index.carbon b/toolchain/semantics/testdata/index/fail_large_index.carbon index 3121ed7d81503..cc3e028267eda 100644 --- a/toolchain/semantics/testdata/index/fail_large_index.carbon +++ b/toolchain/semantics/testdata/index/fail_large_index.carbon @@ -93,3 +93,22 @@ var c: i32 = b[0xFFFFFFFFFFFFFFFFF]; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_13.1: type = tuple_type (type) +// CHECK:STDOUT: %.loc7_13.2: (type,) = tuple_value (%.loc7_9) +// CHECK:STDOUT: %.loc7_13.3: type = tuple_type (i32) +// CHECK:STDOUT: %a: (i32,) = var +// CHECK:STDOUT: %.loc7_18.1: i32 = int_value 12 +// CHECK:STDOUT: %.loc7_18.2: i32 = stub_reference %.loc7_18.1 +// CHECK:STDOUT: %.loc7_21: (i32,) = tuple_value (%.loc7_18.2) +// CHECK:STDOUT: assign %a, %.loc7_21 +// CHECK:STDOUT: %.loc8_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_13: (type,) = tuple_value (%.loc8_9) +// CHECK:STDOUT: %b: (i32,) = var +// CHECK:STDOUT: assign %b, %a +// CHECK:STDOUT: %c: i32 = var +// CHECK:STDOUT: %.loc12: i32 = int_value -1 +// CHECK:STDOUT: assign %c, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_name_not_found.carbon b/toolchain/semantics/testdata/index/fail_name_not_found.carbon index c640c165111f1..6b070bba4fc2a 100644 --- a/toolchain/semantics/testdata/index/fail_name_not_found.carbon +++ b/toolchain/semantics/testdata/index/fail_name_not_found.carbon @@ -52,3 +52,15 @@ fn Main() { // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %b: i32 = var +// CHECK:STDOUT: %.loc11: i32 = int_value 0 +// CHECK:STDOUT: assign %b, +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_negative_indexing.carbon b/toolchain/semantics/testdata/index/fail_negative_indexing.carbon index 39416bbe1aa8a..fab912197d3f3 100644 --- a/toolchain/semantics/testdata/index/fail_negative_indexing.carbon +++ b/toolchain/semantics/testdata/index/fail_negative_indexing.carbon @@ -87,3 +87,6 @@ var b: i32 = a[-10]; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_non_deterministic_type.carbon b/toolchain/semantics/testdata/index/fail_non_deterministic_type.carbon index 222f4c22ef46c..aeb4b43a272f8 100644 --- a/toolchain/semantics/testdata/index/fail_non_deterministic_type.carbon +++ b/toolchain/semantics/testdata/index/fail_non_deterministic_type.carbon @@ -97,3 +97,23 @@ var c: i32 = a[b]; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_14: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_17.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc7_17.2: (type, type) = tuple_value (%.loc7_9, %.loc7_14) +// CHECK:STDOUT: %.loc7_17.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %a: (i32, i32) = var +// CHECK:STDOUT: %.loc7_22.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc7_22.2: i32 = stub_reference %.loc7_22.1 +// CHECK:STDOUT: %.loc7_25.1: i32 = int_value 3 +// CHECK:STDOUT: %.loc7_25.2: i32 = stub_reference %.loc7_25.1 +// CHECK:STDOUT: %.loc7_26: (i32, i32) = tuple_value (%.loc7_22.2, %.loc7_25.2) +// CHECK:STDOUT: assign %a, %.loc7_26 +// CHECK:STDOUT: %b: i32 = var +// CHECK:STDOUT: %.loc8: i32 = int_value 0 +// CHECK:STDOUT: assign %b, %.loc8 +// CHECK:STDOUT: %c: i32 = var +// CHECK:STDOUT: assign %c, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_non_int_indexing.carbon b/toolchain/semantics/testdata/index/fail_non_int_indexing.carbon index cb3741bb7c26b..e3c4400e6974f 100644 --- a/toolchain/semantics/testdata/index/fail_non_int_indexing.carbon +++ b/toolchain/semantics/testdata/index/fail_non_int_indexing.carbon @@ -90,3 +90,21 @@ var b: i32 = a[2.6]; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_14: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_17.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc7_17.2: (type, type) = tuple_value (%.loc7_9, %.loc7_14) +// CHECK:STDOUT: %.loc7_17.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %a: (i32, i32) = var +// CHECK:STDOUT: %.loc7_22.1: i32 = int_value 12 +// CHECK:STDOUT: %.loc7_22.2: i32 = stub_reference %.loc7_22.1 +// CHECK:STDOUT: %.loc7_26.1: i32 = int_value 6 +// CHECK:STDOUT: %.loc7_26.2: i32 = stub_reference %.loc7_26.1 +// CHECK:STDOUT: %.loc7_27: (i32, i32) = tuple_value (%.loc7_22.2, %.loc7_26.2) +// CHECK:STDOUT: assign %a, %.loc7_27 +// CHECK:STDOUT: %b: i32 = var +// CHECK:STDOUT: %.loc11: f64 = real_value 26e-1 +// CHECK:STDOUT: assign %b, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_non_tuple_access.carbon b/toolchain/semantics/testdata/index/fail_non_tuple_access.carbon index baab30f6deda7..001ffb5682352 100644 --- a/toolchain/semantics/testdata/index/fail_non_tuple_access.carbon +++ b/toolchain/semantics/testdata/index/fail_non_tuple_access.carbon @@ -47,3 +47,14 @@ fn Main() { // CHECK:STDOUT: node+3, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_3: i32 = int_value 0 +// CHECK:STDOUT: %.loc11_5: i32 = int_value 1 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/fail_out_of_bound_access.carbon b/toolchain/semantics/testdata/index/fail_out_of_bound_access.carbon index b7fe283c65f4c..b2afc0fb89e86 100644 --- a/toolchain/semantics/testdata/index/fail_out_of_bound_access.carbon +++ b/toolchain/semantics/testdata/index/fail_out_of_bound_access.carbon @@ -89,3 +89,21 @@ var b: i32 = a[2]; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_14: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_17.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc7_17.2: (type, type) = tuple_value (%.loc7_9, %.loc7_14) +// CHECK:STDOUT: %.loc7_17.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %a: (i32, i32) = var +// CHECK:STDOUT: %.loc7_22.1: i32 = int_value 12 +// CHECK:STDOUT: %.loc7_22.2: i32 = stub_reference %.loc7_22.1 +// CHECK:STDOUT: %.loc7_26.1: i32 = int_value 6 +// CHECK:STDOUT: %.loc7_26.2: i32 = stub_reference %.loc7_26.1 +// CHECK:STDOUT: %.loc7_27: (i32, i32) = tuple_value (%.loc7_22.2, %.loc7_26.2) +// CHECK:STDOUT: assign %a, %.loc7_27 +// CHECK:STDOUT: %b: i32 = var +// CHECK:STDOUT: %.loc11: i32 = int_value 2 +// CHECK:STDOUT: assign %b, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/index/return_value_access.carbon b/toolchain/semantics/testdata/index/return_value_access.carbon index 210d0c2d2999c..9e0c54b506830 100644 --- a/toolchain/semantics/testdata/index/return_value_access.carbon +++ b/toolchain/semantics/testdata/index/return_value_access.carbon @@ -84,3 +84,28 @@ fn Run() -> i32 { // CHECK:STDOUT: node+13, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_12: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_16.1: type = tuple_type (type) +// CHECK:STDOUT: %.loc7_16.2: (type,) = tuple_value (%.loc7_12) +// CHECK:STDOUT: %.loc7_16.3: type = tuple_type (i32) +// CHECK:STDOUT: %.loc7_1 = fn_decl @F +// CHECK:STDOUT: %.loc9 = fn_decl @Run +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> (i32,) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc7_28.1: i32 = int_value 0 +// CHECK:STDOUT: %.loc7_28.2: i32 = stub_reference %.loc7_28.1 +// CHECK:STDOUT: %.loc7_30: (i32,) = tuple_value (%.loc7_28.2) +// CHECK:STDOUT: return %.loc7_30 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Run() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc10_11: (i32,) = call @F() +// CHECK:STDOUT: %.loc10_14: i32 = int_value 0 +// CHECK:STDOUT: %.loc10_15: i32 = tuple_index %.loc10_11, %.loc10_14 +// CHECK:STDOUT: return %.loc10_15 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/ir/duplicate_name_same_line.carbon b/toolchain/semantics/testdata/ir/duplicate_name_same_line.carbon new file mode 100644 index 0000000000000..110bee298d2cf --- /dev/null +++ b/toolchain/semantics/testdata/ir/duplicate_name_same_line.carbon @@ -0,0 +1,92 @@ +// 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 +// +// AUTOUPDATE + +fn A() { var n: i32 = 1; if (true) { var n: i32 = 2; } } + +// CHECK:STDOUT: cross_reference_irs_size: 1 +// CHECK:STDOUT: functions: [ +// CHECK:STDOUT: {name: str0, param_refs: block0, body: {block2, block3, block4}}}, +// CHECK:STDOUT: ] +// CHECK:STDOUT: integer_literals: [ +// CHECK:STDOUT: 1, +// CHECK:STDOUT: 2, +// CHECK:STDOUT: ] +// CHECK:STDOUT: real_literals: [ +// CHECK:STDOUT: ] +// CHECK:STDOUT: strings: [ +// CHECK:STDOUT: A, +// CHECK:STDOUT: n, +// CHECK:STDOUT: ] +// CHECK:STDOUT: types: [ +// CHECK:STDOUT: nodeIntegerType, +// CHECK:STDOUT: nodeBoolType, +// CHECK:STDOUT: ] +// CHECK:STDOUT: type_blocks: [ +// CHECK:STDOUT: ] +// CHECK:STDOUT: nodes: [ +// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0}, +// CHECK:STDOUT: {kind: VarStorage, type: type0}, +// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+1, type: type0}, +// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: type0}, +// CHECK:STDOUT: {kind: Assign, arg0: node+1, arg1: node+3}, +// CHECK:STDOUT: {kind: BoolLiteral, arg0: true, type: type1}, +// CHECK:STDOUT: {kind: BranchIf, arg0: block3, arg1: node+5}, +// CHECK:STDOUT: {kind: Branch, arg0: block4}, +// CHECK:STDOUT: {kind: VarStorage, type: type0}, +// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+8, type: type0}, +// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: type0}, +// CHECK:STDOUT: {kind: Assign, arg0: node+8, arg1: node+10}, +// CHECK:STDOUT: {kind: Branch, arg0: block4}, +// CHECK:STDOUT: {kind: Return}, +// CHECK:STDOUT: ] +// CHECK:STDOUT: node_blocks: [ +// CHECK:STDOUT: [ +// CHECK:STDOUT: ], +// CHECK:STDOUT: [ +// CHECK:STDOUT: node+0, +// CHECK:STDOUT: ], +// CHECK:STDOUT: [ +// CHECK:STDOUT: node+1, +// CHECK:STDOUT: node+2, +// CHECK:STDOUT: node+3, +// CHECK:STDOUT: node+4, +// CHECK:STDOUT: node+5, +// CHECK:STDOUT: node+6, +// CHECK:STDOUT: node+7, +// CHECK:STDOUT: ], +// CHECK:STDOUT: [ +// CHECK:STDOUT: node+8, +// CHECK:STDOUT: node+9, +// CHECK:STDOUT: node+10, +// CHECK:STDOUT: node+11, +// CHECK:STDOUT: node+12, +// CHECK:STDOUT: ], +// CHECK:STDOUT: [ +// CHECK:STDOUT: node+13, +// CHECK:STDOUT: ], +// CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @A +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @A() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %n.loc7_14: i32 = var +// CHECK:STDOUT: %.loc7_23: i32 = int_value 1 +// CHECK:STDOUT: assign %n.loc7_14, %.loc7_23 +// CHECK:STDOUT: %.loc7_30: bool = bool_value true +// CHECK:STDOUT: if %.loc7_30 br !.loc7_42 else br !.loc7_56 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc7_42: +// CHECK:STDOUT: %n.loc7_42: i32 = var +// CHECK:STDOUT: %.loc7_51: i32 = int_value 2 +// CHECK:STDOUT: assign %n.loc7_42, %.loc7_51 +// CHECK:STDOUT: br !.loc7_56 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc7_56: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/namespace/fail_duplicate.carbon b/toolchain/semantics/testdata/namespace/fail_duplicate.carbon index b22d7fec49518..e1c864e7673ba 100644 --- a/toolchain/semantics/testdata/namespace/fail_duplicate.carbon +++ b/toolchain/semantics/testdata/namespace/fail_duplicate.carbon @@ -21,7 +21,7 @@ fn Foo.Baz() { // CHECK:STDOUT: cross_reference_irs_size: 1 // CHECK:STDOUT: functions: [ // CHECK:STDOUT: {name: str1, param_refs: block0, body: {block2}}}, -// CHECK:STDOUT: {name: str7, param_refs: block0, body: {block3}}}, +// CHECK:STDOUT: {name: str, param_refs: block0, body: {block3}}}, // CHECK:STDOUT: ] // CHECK:STDOUT: integer_literals: [ // CHECK:STDOUT: ] @@ -57,3 +57,19 @@ fn Foo.Baz() { // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = namespace {.Baz = %.loc9} +// CHECK:STDOUT: %.loc9 = fn_decl @Baz +// CHECK:STDOUT: %.loc18 = fn_decl @.1 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Baz() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @.1() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/namespace/fail_unresolved_scope.carbon b/toolchain/semantics/testdata/namespace/fail_unresolved_scope.carbon index 8db80a792b116..65d91e8df725e 100644 --- a/toolchain/semantics/testdata/namespace/fail_unresolved_scope.carbon +++ b/toolchain/semantics/testdata/namespace/fail_unresolved_scope.carbon @@ -40,3 +40,12 @@ fn Foo.Baz() { // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10 = fn_decl @.1 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @.1() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/namespace/function.carbon b/toolchain/semantics/testdata/namespace/function.carbon index a3b0fc978d0cb..a31971d86dd7e 100644 --- a/toolchain/semantics/testdata/namespace/function.carbon +++ b/toolchain/semantics/testdata/namespace/function.carbon @@ -71,3 +71,27 @@ fn Bar() { // CHECK:STDOUT: node+8, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = namespace {.Baz = %.loc13} +// CHECK:STDOUT: %.loc10 = fn_decl @Baz.1 +// CHECK:STDOUT: %.loc13 = fn_decl @Baz.2 +// CHECK:STDOUT: %.loc16 = fn_decl @Bar +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Baz.1() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Baz.2() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Bar() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc17_10.1: type = tuple_type () +// CHECK:STDOUT: %.loc17_10.2: () = call @Baz.2() +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/namespace/nested.carbon b/toolchain/semantics/testdata/namespace/nested.carbon index 46d2551538f7b..8b6f9bb49f4e1 100644 --- a/toolchain/semantics/testdata/namespace/nested.carbon +++ b/toolchain/semantics/testdata/namespace/nested.carbon @@ -64,3 +64,22 @@ fn Foo.Bar.Baz() { // CHECK:STDOUT: node+7, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = namespace {.Bar = %.loc8} +// CHECK:STDOUT: %.loc8 = namespace {.Wiz = %.loc10, .Baz = %.loc13} +// CHECK:STDOUT: %.loc10 = fn_decl @Wiz +// CHECK:STDOUT: %.loc13 = fn_decl @Baz +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Wiz() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Baz() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc14_14.1: type = tuple_type () +// CHECK:STDOUT: %.loc14_14.2: () = call @Wiz() +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/and.carbon b/toolchain/semantics/testdata/operators/and.carbon index cb050b6b74856..19c4686d49688 100644 --- a/toolchain/semantics/testdata/operators/and.carbon +++ b/toolchain/semantics/testdata/operators/and.carbon @@ -79,3 +79,36 @@ fn And() -> bool { // CHECK:STDOUT: node+14, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: %.loc8 = fn_decl @G +// CHECK:STDOUT: %.loc10 = fn_decl @And +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> bool { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc7: bool = bool_value true +// CHECK:STDOUT: return %.loc7 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G() -> bool { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8: bool = bool_value true +// CHECK:STDOUT: return %.loc8 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @And() -> bool { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_11: bool = call @F() +// CHECK:STDOUT: %.loc11_14.1: bool = bool_value false +// CHECK:STDOUT: if %.loc11_11 br !.loc11_19 else br !.loc11_14(%.loc11_14.1) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_19: +// CHECK:STDOUT: %.loc11_19: bool = call @G() +// CHECK:STDOUT: br !.loc11_14(%.loc11_19) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_14: +// CHECK:STDOUT: %.loc11_14.2: bool = block_arg !.loc11_14 +// CHECK:STDOUT: return %.loc11_14.2 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/assignment.carbon b/toolchain/semantics/testdata/operators/assignment.carbon index f7d1dfa47c0e5..473f961ebcd20 100644 --- a/toolchain/semantics/testdata/operators/assignment.carbon +++ b/toolchain/semantics/testdata/operators/assignment.carbon @@ -235,3 +235,73 @@ fn Main() { // CHECK:STDOUT: node+65, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %a: i32 = var +// CHECK:STDOUT: %.loc8: i32 = int_value 12 +// CHECK:STDOUT: assign %a, %.loc8 +// CHECK:STDOUT: %.loc9: i32 = int_value -7 +// CHECK:STDOUT: assign %a, %.loc9 +// CHECK:STDOUT: %.loc11_11: type = stub_reference i32 +// CHECK:STDOUT: %.loc11_16: type = stub_reference i32 +// CHECK:STDOUT: %.loc11_19.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc11_19.2: (type, type) = tuple_value (%.loc11_11, %.loc11_16) +// CHECK:STDOUT: %.loc11_19.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %b: (i32, i32) = var +// CHECK:STDOUT: %.loc11_24.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc11_24.2: i32 = stub_reference %.loc11_24.1 +// CHECK:STDOUT: %.loc11_27.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc11_27.2: i32 = stub_reference %.loc11_27.1 +// CHECK:STDOUT: %.loc11_28: (i32, i32) = tuple_value (%.loc11_24.2, %.loc11_27.2) +// CHECK:STDOUT: assign %b, %.loc11_28 +// CHECK:STDOUT: %.loc12_5: i32 = int_value 0 +// CHECK:STDOUT: %.loc12_6: i32 = tuple_index %b, %.loc12_5 +// CHECK:STDOUT: %.loc12_10: i32 = int_value 3 +// CHECK:STDOUT: assign %.loc12_6, %.loc12_10 +// CHECK:STDOUT: %.loc13_5: i32 = int_value 1 +// CHECK:STDOUT: %.loc13_6: i32 = tuple_index %b, %.loc13_5 +// CHECK:STDOUT: %.loc13_10: i32 = int_value 4 +// CHECK:STDOUT: assign %.loc13_6, %.loc13_10 +// CHECK:STDOUT: %.loc15_27: type = struct_type {.a: i32, .b: i32} +// CHECK:STDOUT: %c: {.a: i32, .b: i32} = var +// CHECK:STDOUT: %.loc15_37: i32 = int_value 1 +// CHECK:STDOUT: %.loc15_35: i32 = stub_reference %.loc15_37 +// CHECK:STDOUT: %.loc15_45: i32 = int_value 2 +// CHECK:STDOUT: %.loc15_43: i32 = stub_reference %.loc15_45 +// CHECK:STDOUT: %.loc15_46: {.a: i32, .b: i32} = struct_value (%.loc15_35, %.loc15_43) +// CHECK:STDOUT: assign %c, %.loc15_46 +// CHECK:STDOUT: %.loc16_4: i32 = struct_access %c, member0 +// CHECK:STDOUT: %.loc16_9: i32 = int_value 3 +// CHECK:STDOUT: assign %.loc16_4, %.loc16_9 +// CHECK:STDOUT: %.loc17_4: i32 = struct_access %c, member1 +// CHECK:STDOUT: %.loc17_9: i32 = int_value 4 +// CHECK:STDOUT: assign %.loc17_4, %.loc17_9 +// CHECK:STDOUT: %.loc19_13: type = ptr_type i32 +// CHECK:STDOUT: %p: i32* = var +// CHECK:STDOUT: %.loc19_17: i32* = address_of %a +// CHECK:STDOUT: assign %p, %.loc19_17 +// CHECK:STDOUT: %.loc20_3: i32 = dereference %p +// CHECK:STDOUT: %.loc20_8: i32 = int_value 5 +// CHECK:STDOUT: assign %.loc20_3, %.loc20_8 +// CHECK:STDOUT: %.loc22_8: bool = bool_value true +// CHECK:STDOUT: if %.loc22_8 br !.loc22_5.1 else br !.loc22_25 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc22_5.1: +// CHECK:STDOUT: br !.loc22_5.2(%p) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc22_25: +// CHECK:STDOUT: %.loc22_25: i32* = address_of %a +// CHECK:STDOUT: br !.loc22_5.2(%.loc22_25) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc22_5.2: +// CHECK:STDOUT: %.loc22_5: i32* = block_arg !.loc22_5.2 +// CHECK:STDOUT: %.loc22_3: i32 = dereference %.loc22_5 +// CHECK:STDOUT: %.loc22_31: i32 = int_value 10 +// CHECK:STDOUT: assign %.loc22_3, %.loc22_31 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/binary_op.carbon b/toolchain/semantics/testdata/operators/binary_op.carbon index 22d6fd697f34e..9b3caa65a228c 100644 --- a/toolchain/semantics/testdata/operators/binary_op.carbon +++ b/toolchain/semantics/testdata/operators/binary_op.carbon @@ -46,3 +46,15 @@ fn Main() -> i32 { // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8_10: i32 = int_value 12 +// CHECK:STDOUT: %.loc8_15: i32 = int_value 34 +// CHECK:STDOUT: %.loc8_13: i32 = add %.loc8_10, %.loc8_15 +// CHECK:STDOUT: return %.loc8_13 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/fail_assigment_to_non_assignable.carbon b/toolchain/semantics/testdata/operators/fail_assigment_to_non_assignable.carbon index ae4fbf9a0d4f5..dff50409dceef 100644 --- a/toolchain/semantics/testdata/operators/fail_assigment_to_non_assignable.carbon +++ b/toolchain/semantics/testdata/operators/fail_assigment_to_non_assignable.carbon @@ -286,3 +286,88 @@ fn Main() { // CHECK:STDOUT: node+71, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> i32; +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc13_3: i32 = int_value 1 +// CHECK:STDOUT: %.loc13_7: i32 = int_value 2 +// CHECK:STDOUT: assign %.loc13_3, %.loc13_7 +// CHECK:STDOUT: %.loc17_4: i32 = call @F() +// CHECK:STDOUT: %.loc17_9: i32 = int_value 1 +// CHECK:STDOUT: assign %.loc17_4, %.loc17_9 +// CHECK:STDOUT: %.loc21_4.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc21_4.2: i32 = stub_reference %.loc21_4.1 +// CHECK:STDOUT: %.loc21_7.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc21_7.2: i32 = stub_reference %.loc21_7.1 +// CHECK:STDOUT: %.loc21_8.1: type = tuple_type (i32, i32) +// CHECK:STDOUT: %.loc21_8.2: (i32, i32) = tuple_value (%.loc21_4.2, %.loc21_7.2) +// CHECK:STDOUT: %.loc21_13.1: i32 = int_value 3 +// CHECK:STDOUT: %.loc21_13.2: i32 = stub_reference %.loc21_13.1 +// CHECK:STDOUT: %.loc21_16.1: i32 = int_value 4 +// CHECK:STDOUT: %.loc21_16.2: i32 = stub_reference %.loc21_16.1 +// CHECK:STDOUT: %.loc21_17: (i32, i32) = tuple_value (%.loc21_13.2, %.loc21_16.2) +// CHECK:STDOUT: assign %.loc21_8.2, %.loc21_17 +// CHECK:STDOUT: %n: i32 = var +// CHECK:STDOUT: %.loc22: i32 = int_value 0 +// CHECK:STDOUT: assign %n, %.loc22 +// CHECK:STDOUT: %.loc26_4: i32 = stub_reference %n +// CHECK:STDOUT: %.loc26_7: i32 = stub_reference %n +// CHECK:STDOUT: %.loc26_8: (i32, i32) = tuple_value (%.loc26_4, %.loc26_7) +// CHECK:STDOUT: %.loc26_13.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc26_13.2: i32 = stub_reference %.loc26_13.1 +// CHECK:STDOUT: %.loc26_16.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc26_16.2: i32 = stub_reference %.loc26_16.1 +// CHECK:STDOUT: %.loc26_17: (i32, i32) = tuple_value (%.loc26_13.2, %.loc26_16.2) +// CHECK:STDOUT: assign %.loc26_8, %.loc26_17 +// CHECK:STDOUT: %.loc30: type = ptr_type i32 +// CHECK:STDOUT: assign i32, %.loc30 +// CHECK:STDOUT: %.loc34_9: i32 = int_value 1 +// CHECK:STDOUT: %.loc34_7: i32 = stub_reference %.loc34_9 +// CHECK:STDOUT: %.loc34_17: i32 = int_value 2 +// CHECK:STDOUT: %.loc34_15: i32 = stub_reference %.loc34_17 +// CHECK:STDOUT: %.loc34_18.1: type = struct_type {.x: i32, .y: i32} +// CHECK:STDOUT: %.loc34_18.2: {.x: i32, .y: i32} = struct_value (%.loc34_7, %.loc34_15) +// CHECK:STDOUT: %.loc34_28: i32 = int_value 3 +// CHECK:STDOUT: %.loc34_26: i32 = stub_reference %.loc34_28 +// CHECK:STDOUT: %.loc34_36: i32 = int_value 4 +// CHECK:STDOUT: %.loc34_34: i32 = stub_reference %.loc34_36 +// CHECK:STDOUT: %.loc34_37: {.x: i32, .y: i32} = struct_value (%.loc34_26, %.loc34_34) +// CHECK:STDOUT: assign %.loc34_18.2, %.loc34_37 +// CHECK:STDOUT: %.loc38_7: bool = bool_value true +// CHECK:STDOUT: if %.loc38_7 br !.loc38_17 else br !.loc38_24 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc38_17: +// CHECK:STDOUT: %.loc38_17: i32 = int_value 1 +// CHECK:STDOUT: br !.loc38_4(%.loc38_17) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc38_24: +// CHECK:STDOUT: %.loc38_24: i32 = int_value 2 +// CHECK:STDOUT: br !.loc38_4(%.loc38_24) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc38_4: +// CHECK:STDOUT: %.loc38_4: i32 = block_arg !.loc38_4 +// CHECK:STDOUT: %.loc38_29: i32 = int_value 3 +// CHECK:STDOUT: assign %.loc38_4, %.loc38_29 +// CHECK:STDOUT: %a: i32 = var +// CHECK:STDOUT: %.loc45_7: bool = bool_value true +// CHECK:STDOUT: if %.loc45_7 br !.loc45_4.1 else br !.loc45_4.2 +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc45_4.1: +// CHECK:STDOUT: br !.loc45_4.3(%a) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc45_4.2: +// CHECK:STDOUT: br !.loc45_4.3(%a) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc45_4.3: +// CHECK:STDOUT: %.loc45_4: i32 = block_arg !.loc45_4.3 +// CHECK:STDOUT: %.loc45_29: i32 = int_value 10 +// CHECK:STDOUT: assign %.loc45_4, %.loc45_29 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/fail_type_mismatch.carbon b/toolchain/semantics/testdata/operators/fail_type_mismatch.carbon index 0986566d43376..7549495fa0dbe 100644 --- a/toolchain/semantics/testdata/operators/fail_type_mismatch.carbon +++ b/toolchain/semantics/testdata/operators/fail_type_mismatch.carbon @@ -50,3 +50,15 @@ fn Main() -> i32 { // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_10: i32 = int_value 12 +// CHECK:STDOUT: %.loc11_15: f64 = real_value 34e-1 +// CHECK:STDOUT: %.loc11_13: = add , %.loc11_15 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/fail_type_mismatch_assignment.carbon b/toolchain/semantics/testdata/operators/fail_type_mismatch_assignment.carbon index 3730860389fb4..1d9942f4d7305 100644 --- a/toolchain/semantics/testdata/operators/fail_type_mismatch_assignment.carbon +++ b/toolchain/semantics/testdata/operators/fail_type_mismatch_assignment.carbon @@ -58,3 +58,17 @@ fn Main() { // CHECK:STDOUT: node+7, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %a: i32 = var +// CHECK:STDOUT: %.loc8: i32 = int_value 3 +// CHECK:STDOUT: assign %a, %.loc8 +// CHECK:STDOUT: %.loc12: f64 = real_value 56e-1 +// CHECK:STDOUT: assign %a, %.loc12 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/fail_type_mismatch_once.carbon b/toolchain/semantics/testdata/operators/fail_type_mismatch_once.carbon index 8f67cb86d4ac1..5de659b8f323b 100644 --- a/toolchain/semantics/testdata/operators/fail_type_mismatch_once.carbon +++ b/toolchain/semantics/testdata/operators/fail_type_mismatch_once.carbon @@ -57,3 +57,17 @@ fn Main() -> i32 { // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc13_10: i32 = int_value 12 +// CHECK:STDOUT: %.loc13_15: f64 = real_value 34e-1 +// CHECK:STDOUT: %.loc13_13: = add , %.loc13_15 +// CHECK:STDOUT: %.loc13_21: i32 = int_value 12 +// CHECK:STDOUT: %.loc13_19: = add , %.loc13_21 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/or.carbon b/toolchain/semantics/testdata/operators/or.carbon index e43fcc181caf2..44a92ec5b7303 100644 --- a/toolchain/semantics/testdata/operators/or.carbon +++ b/toolchain/semantics/testdata/operators/or.carbon @@ -81,3 +81,37 @@ fn Or() -> bool { // CHECK:STDOUT: node+15, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: %.loc8 = fn_decl @G +// CHECK:STDOUT: %.loc10 = fn_decl @Or +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> bool { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc7: bool = bool_value true +// CHECK:STDOUT: return %.loc7 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G() -> bool { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8: bool = bool_value true +// CHECK:STDOUT: return %.loc8 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Or() -> bool { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_11: bool = call @F() +// CHECK:STDOUT: %.loc11_14.1: bool = not %.loc11_11 +// CHECK:STDOUT: %.loc11_14.2: bool = bool_value true +// CHECK:STDOUT: if %.loc11_14.1 br !.loc11_18 else br !.loc11_14(%.loc11_14.2) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_18: +// CHECK:STDOUT: %.loc11_18: bool = call @G() +// CHECK:STDOUT: br !.loc11_14(%.loc11_18) +// CHECK:STDOUT: +// CHECK:STDOUT: !.loc11_14: +// CHECK:STDOUT: %.loc11_14.3: bool = block_arg !.loc11_14 +// CHECK:STDOUT: return %.loc11_14.3 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/operators/unary_op.carbon b/toolchain/semantics/testdata/operators/unary_op.carbon index d5f60c693f920..e5f8796cae8ff 100644 --- a/toolchain/semantics/testdata/operators/unary_op.carbon +++ b/toolchain/semantics/testdata/operators/unary_op.carbon @@ -50,3 +50,13 @@ fn Not(b: bool) -> bool { // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Not +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Not(%b: bool) -> bool { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8: bool = not %b +// CHECK:STDOUT: return %.loc8 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/address_of_deref.carbon b/toolchain/semantics/testdata/pointer/address_of_deref.carbon index 1e6a0f30cdb59..0a9799d23b7fd 100644 --- a/toolchain/semantics/testdata/pointer/address_of_deref.carbon +++ b/toolchain/semantics/testdata/pointer/address_of_deref.carbon @@ -60,3 +60,20 @@ fn F() -> i32 { // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %n: i32 = var +// CHECK:STDOUT: %.loc8: i32 = int_value 0 +// CHECK:STDOUT: assign %n, %.loc8 +// CHECK:STDOUT: %.loc9_13.1: type = ptr_type i32 +// CHECK:STDOUT: %.loc9_13.2: i32* = address_of %n +// CHECK:STDOUT: %.loc9_12: i32 = dereference %.loc9_13.2 +// CHECK:STDOUT: %.loc9_11: i32* = address_of %.loc9_12 +// CHECK:STDOUT: %.loc9_10: i32 = dereference %.loc9_11 +// CHECK:STDOUT: return %.loc9_10 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/address_of_lvalue.carbon b/toolchain/semantics/testdata/pointer/address_of_lvalue.carbon index 29c555780be66..1df4eb8d9a100 100644 --- a/toolchain/semantics/testdata/pointer/address_of_lvalue.carbon +++ b/toolchain/semantics/testdata/pointer/address_of_lvalue.carbon @@ -239,3 +239,62 @@ fn F(param: i32) { // CHECK:STDOUT: node+45, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(%param: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8_27: type = struct_type {.a: i32, .b: i32} +// CHECK:STDOUT: %s: {.a: i32, .b: i32} = var +// CHECK:STDOUT: %.loc8_37: i32 = int_value 1 +// CHECK:STDOUT: %.loc8_35: i32 = stub_reference %.loc8_37 +// CHECK:STDOUT: %.loc8_45: i32 = int_value 2 +// CHECK:STDOUT: %.loc8_43: i32 = stub_reference %.loc8_45 +// CHECK:STDOUT: %.loc8_46: {.a: i32, .b: i32} = struct_value (%.loc8_35, %.loc8_43) +// CHECK:STDOUT: assign %s, %.loc8_46 +// CHECK:STDOUT: %.loc10_28: type = ptr_type {.a: i32, .b: i32} +// CHECK:STDOUT: %p: {.a: i32, .b: i32}* = var +// CHECK:STDOUT: %.loc10_32: {.a: i32, .b: i32}* = address_of %s +// CHECK:STDOUT: assign %p, %.loc10_32 +// CHECK:STDOUT: %.loc11_13: type = ptr_type i32 +// CHECK:STDOUT: %q: i32* = var +// CHECK:STDOUT: %.loc11_19: i32 = struct_access %s, member0 +// CHECK:STDOUT: %.loc11_17: i32* = address_of %.loc11_19 +// CHECK:STDOUT: assign %q, %.loc11_17 +// CHECK:STDOUT: %.loc12_13: type = ptr_type i32 +// CHECK:STDOUT: %r: i32* = var +// CHECK:STDOUT: %.loc12_19: i32 = struct_access %s, member1 +// CHECK:STDOUT: %.loc12_17: i32* = address_of %.loc12_19 +// CHECK:STDOUT: assign %r, %.loc12_17 +// CHECK:STDOUT: %.loc14_11: type = stub_reference i32 +// CHECK:STDOUT: %.loc14_16: type = stub_reference i32 +// CHECK:STDOUT: %.loc14_19.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc14_19.2: (type, type) = tuple_value (%.loc14_11, %.loc14_16) +// CHECK:STDOUT: %.loc14_19.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %t: (i32, i32) = var +// CHECK:STDOUT: %.loc14_24.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc14_24.2: i32 = stub_reference %.loc14_24.1 +// CHECK:STDOUT: %.loc14_27.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc14_27.2: i32 = stub_reference %.loc14_27.1 +// CHECK:STDOUT: %.loc14_28: (i32, i32) = tuple_value (%.loc14_24.2, %.loc14_27.2) +// CHECK:STDOUT: assign %t, %.loc14_28 +// CHECK:STDOUT: %.loc15_14: type = ptr_type i32 +// CHECK:STDOUT: %t0: i32* = var +// CHECK:STDOUT: %.loc15_21: i32 = int_value 0 +// CHECK:STDOUT: %.loc15_22: i32 = tuple_index %t, %.loc15_21 +// CHECK:STDOUT: %.loc15_18: i32* = address_of %.loc15_22 +// CHECK:STDOUT: assign %t0, %.loc15_18 +// CHECK:STDOUT: %.loc16_14: type = ptr_type i32 +// CHECK:STDOUT: %t1: i32* = var +// CHECK:STDOUT: %.loc16_21: i32 = int_value 1 +// CHECK:STDOUT: %.loc16_22: i32 = tuple_index %t, %.loc16_21 +// CHECK:STDOUT: %.loc16_18: i32* = address_of %.loc16_22 +// CHECK:STDOUT: assign %t1, %.loc16_18 +// CHECK:STDOUT: %.loc20_22: type = ptr_type i32 +// CHECK:STDOUT: %param_addr: i32* = var +// CHECK:STDOUT: %.loc20_26: i32* = address_of %param +// CHECK:STDOUT: assign %param_addr, %.loc20_26 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/basic.carbon b/toolchain/semantics/testdata/pointer/basic.carbon index e2f48282866b0..8ca0c16fb4493 100644 --- a/toolchain/semantics/testdata/pointer/basic.carbon +++ b/toolchain/semantics/testdata/pointer/basic.carbon @@ -65,3 +65,20 @@ fn F() -> i32 { // CHECK:STDOUT: node+11, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %n: i32 = var +// CHECK:STDOUT: %.loc8: i32 = int_value 0 +// CHECK:STDOUT: assign %n, %.loc8 +// CHECK:STDOUT: %.loc9_13: type = ptr_type i32 +// CHECK:STDOUT: %p: i32* = var +// CHECK:STDOUT: %.loc9_17: i32* = address_of %n +// CHECK:STDOUT: assign %p, %.loc9_17 +// CHECK:STDOUT: %.loc11: i32 = dereference %p +// CHECK:STDOUT: return %.loc11 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/fail_address_of_value.carbon b/toolchain/semantics/testdata/pointer/fail_address_of_value.carbon index 1520b2c5fc562..22243e8267c0b 100644 --- a/toolchain/semantics/testdata/pointer/fail_address_of_value.carbon +++ b/toolchain/semantics/testdata/pointer/fail_address_of_value.carbon @@ -296,3 +296,93 @@ fn AddressOfTupleElementValue() { // CHECK:STDOUT: node+59, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @G +// CHECK:STDOUT: %.loc9_19: type = struct_type {.a: i32} +// CHECK:STDOUT: %.loc9_1 = fn_decl @H +// CHECK:STDOUT: %.loc11 = fn_decl @AddressOfLiteral +// CHECK:STDOUT: %.loc38 = fn_decl @AddressOfOperator +// CHECK:STDOUT: %.loc53 = fn_decl @AddressOfCall +// CHECK:STDOUT: %.loc60 = fn_decl @AddressOfType +// CHECK:STDOUT: %.loc71 = fn_decl @AddressOfTupleElementValue +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @G() -> i32; +// CHECK:STDOUT: +// CHECK:STDOUT: fn @H() -> {.a: i32}; +// CHECK:STDOUT: +// CHECK:STDOUT: fn @AddressOfLiteral() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc15_4: i32 = int_value 0 +// CHECK:STDOUT: %.loc15_3.1: type = ptr_type i32 +// CHECK:STDOUT: %.loc15_3.2: i32* = address_of %.loc15_4 +// CHECK:STDOUT: %.loc19_4: bool = bool_value true +// CHECK:STDOUT: %.loc19_3.1: type = ptr_type bool +// CHECK:STDOUT: %.loc19_3.2: bool* = address_of %.loc19_4 +// CHECK:STDOUT: %.loc23_4: f64 = real_value 10e-1 +// CHECK:STDOUT: %.loc23_3.1: type = ptr_type f64 +// CHECK:STDOUT: %.loc23_3.2: f64* = address_of %.loc23_4 +// CHECK:STDOUT: %.loc27_4: String = string_value "Hello" +// CHECK:STDOUT: %.loc27_3.1: type = ptr_type String +// CHECK:STDOUT: %.loc27_3.2: String* = address_of %.loc27_4 +// CHECK:STDOUT: %.loc31_5.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc31_5.2: i32 = stub_reference %.loc31_5.1 +// CHECK:STDOUT: %.loc31_8.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc31_8.2: i32 = stub_reference %.loc31_8.1 +// CHECK:STDOUT: %.loc31_9.1: type = tuple_type (i32, i32) +// CHECK:STDOUT: %.loc31_9.2: (i32, i32) = tuple_value (%.loc31_5.2, %.loc31_8.2) +// CHECK:STDOUT: %.loc31_3.1: type = ptr_type (i32, i32) +// CHECK:STDOUT: %.loc31_3.2: (i32, i32)* = address_of %.loc31_9.2 +// CHECK:STDOUT: %.loc35_10: i32 = int_value 5 +// CHECK:STDOUT: %.loc35_8: i32 = stub_reference %.loc35_10 +// CHECK:STDOUT: %.loc35_11: {.a: i32} = struct_value (%.loc35_8) +// CHECK:STDOUT: %.loc35_3.1: type = ptr_type {.a: i32} +// CHECK:STDOUT: %.loc35_3.2: {.a: i32}* = address_of %.loc35_11 +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @AddressOfOperator() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc42_5: i32 = int_value 1 +// CHECK:STDOUT: %.loc42_9: i32 = int_value 1 +// CHECK:STDOUT: %.loc42_7: i32 = add %.loc42_5, %.loc42_9 +// CHECK:STDOUT: %.loc42_3: i32* = address_of %.loc42_7 +// CHECK:STDOUT: %.loc46_5: {.a: i32} = call @H() +// CHECK:STDOUT: %.loc46_7: i32 = struct_access %.loc46_5, member0 +// CHECK:STDOUT: %.loc46_3: i32* = address_of %.loc46_7 +// CHECK:STDOUT: %.loc50_9: bool = bool_value true +// CHECK:STDOUT: %.loc50_5: bool = not %.loc50_9 +// CHECK:STDOUT: %.loc50_3: bool* = address_of %.loc50_5 +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @AddressOfCall() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc57_5: i32 = call @G() +// CHECK:STDOUT: %.loc57_3: i32* = address_of %.loc57_5 +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @AddressOfType() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc64_3.1: type = ptr_type type +// CHECK:STDOUT: %.loc64_3.2: type* = address_of i32 +// CHECK:STDOUT: %.loc68_5: type = const_type i32 +// CHECK:STDOUT: %.loc68_14: type = ptr_type const i32 +// CHECK:STDOUT: %.loc68_3: type* = address_of %.loc68_14 +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @AddressOfTupleElementValue() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc75_6.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc75_6.2: i32 = stub_reference %.loc75_6.1 +// CHECK:STDOUT: %.loc75_9.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc75_9.2: i32 = stub_reference %.loc75_9.1 +// CHECK:STDOUT: %.loc75_10: (i32, i32) = tuple_value (%.loc75_6.2, %.loc75_9.2) +// CHECK:STDOUT: %.loc75_12: i32 = int_value 0 +// CHECK:STDOUT: %.loc75_13: i32 = tuple_index %.loc75_10, %.loc75_12 +// CHECK:STDOUT: %.loc75_3: i32* = address_of %.loc75_13 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/fail_dereference_not_pointer.carbon b/toolchain/semantics/testdata/pointer/fail_dereference_not_pointer.carbon index fdb25ec39acf9..0c5f7d5ac4617 100644 --- a/toolchain/semantics/testdata/pointer/fail_dereference_not_pointer.carbon +++ b/toolchain/semantics/testdata/pointer/fail_dereference_not_pointer.carbon @@ -77,3 +77,19 @@ fn Deref(n: i32) { // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Deref +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Deref(%n: i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11: = dereference %n +// CHECK:STDOUT: %.loc15_5.1: type = tuple_type () +// CHECK:STDOUT: %.loc15_5.2: () = tuple_value () +// CHECK:STDOUT: %.loc15_3: = dereference %.loc15_5.2 +// CHECK:STDOUT: %.loc19_5.1: type = struct_type {} +// CHECK:STDOUT: %.loc19_5.2: {} = struct_value () +// CHECK:STDOUT: %.loc19_3: = dereference %.loc19_5.2 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/fail_dereference_type.carbon b/toolchain/semantics/testdata/pointer/fail_dereference_type.carbon index bf15150f49685..acde72db7d927 100644 --- a/toolchain/semantics/testdata/pointer/fail_dereference_type.carbon +++ b/toolchain/semantics/testdata/pointer/fail_dereference_type.carbon @@ -40,3 +40,8 @@ var p: *i32; // CHECK:STDOUT: node+2, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc13: = dereference i32 +// CHECK:STDOUT: %p: = var +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/fail_type_mismatch.carbon b/toolchain/semantics/testdata/pointer/fail_type_mismatch.carbon index 028578288ea1f..0ac95bf2aacd6 100644 --- a/toolchain/semantics/testdata/pointer/fail_type_mismatch.carbon +++ b/toolchain/semantics/testdata/pointer/fail_type_mismatch.carbon @@ -69,3 +69,15 @@ fn ConstMismatch(p: const {}*) -> const ({}*) { // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_43: {} = struct_value () +// CHECK:STDOUT: %.loc7_44: type = ptr_type {} +// CHECK:STDOUT: %.loc7_35: type = const_type {}* +// CHECK:STDOUT: %.loc7_1 = fn_decl @ConstMismatch +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @ConstMismatch(%p: const {}*) -> const ({}*) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/nested_const.carbon b/toolchain/semantics/testdata/pointer/nested_const.carbon index 46738c346b5cc..ac7b941a79cbd 100644 --- a/toolchain/semantics/testdata/pointer/nested_const.carbon +++ b/toolchain/semantics/testdata/pointer/nested_const.carbon @@ -70,3 +70,15 @@ fn F(p: const (const (const i32*)*)) -> const i32 { // CHECK:STDOUT: node+11, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc8_41: type = const_type i32 +// CHECK:STDOUT: %.loc8_1 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(%p: const (const (const i32*)*)) -> const i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc9_11: const (const i32*) = dereference %p +// CHECK:STDOUT: %.loc9_10: const i32 = dereference %.loc9_11 +// CHECK:STDOUT: return %.loc9_10 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/pointer/types.carbon b/toolchain/semantics/testdata/pointer/types.carbon index 71b1b9e03093b..23d19e82b8ec9 100644 --- a/toolchain/semantics/testdata/pointer/types.carbon +++ b/toolchain/semantics/testdata/pointer/types.carbon @@ -84,3 +84,21 @@ fn ConstPtr(p: const i32*) -> (const i32)* { // CHECK:STDOUT: node+13, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_23: type = ptr_type i32 +// CHECK:STDOUT: %.loc7_1 = fn_decl @Ptr +// CHECK:STDOUT: %.loc11_32: type = const_type i32 +// CHECK:STDOUT: %.loc11_42: type = ptr_type const i32 +// CHECK:STDOUT: %.loc11_1 = fn_decl @ConstPtr +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Ptr(%p: i32*) -> i32* { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return %p +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @ConstPtr(%p: const i32*) -> const i32* { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return %p +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/code_after_return.carbon b/toolchain/semantics/testdata/return/code_after_return.carbon index ca2bae75d0569..8f41406739118 100644 --- a/toolchain/semantics/testdata/return/code_after_return.carbon +++ b/toolchain/semantics/testdata/return/code_after_return.carbon @@ -48,3 +48,12 @@ fn Main() { // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/code_after_return_value.carbon b/toolchain/semantics/testdata/return/code_after_return_value.carbon index 3e76c6b7ff19e..c761ed713fb19 100644 --- a/toolchain/semantics/testdata/return/code_after_return_value.carbon +++ b/toolchain/semantics/testdata/return/code_after_return_value.carbon @@ -77,3 +77,13 @@ fn F(b: bool) -> i32 { // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F(%b: bool) -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8: i32 = int_value 0 +// CHECK:STDOUT: return %.loc8 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/fail_missing_return.carbon b/toolchain/semantics/testdata/return/fail_missing_return.carbon index 51007d2af1cc6..97a66bd536a4c 100644 --- a/toolchain/semantics/testdata/return/fail_missing_return.carbon +++ b/toolchain/semantics/testdata/return/fail_missing_return.carbon @@ -38,3 +38,11 @@ fn Main() -> i32 { // CHECK:STDOUT: [ // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/fail_missing_return_empty_tuple.carbon b/toolchain/semantics/testdata/return/fail_missing_return_empty_tuple.carbon index b438edc463064..579e03d22dee8 100644 --- a/toolchain/semantics/testdata/return/fail_missing_return_empty_tuple.carbon +++ b/toolchain/semantics/testdata/return/fail_missing_return_empty_tuple.carbon @@ -44,3 +44,13 @@ fn F() -> () { // CHECK:STDOUT: [ // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_12.1: type = tuple_type () +// CHECK:STDOUT: %.loc7_12.2: () = tuple_value () +// CHECK:STDOUT: %.loc7_1 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() -> () { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/fail_type_mismatch.carbon b/toolchain/semantics/testdata/return/fail_type_mismatch.carbon index 985262c39757c..63c546a009fe4 100644 --- a/toolchain/semantics/testdata/return/fail_type_mismatch.carbon +++ b/toolchain/semantics/testdata/return/fail_type_mismatch.carbon @@ -45,3 +45,13 @@ fn Main() -> i32 { // CHECK:STDOUT: node+2, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11: f64 = real_value 10e-1 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/fail_value_disallowed.carbon b/toolchain/semantics/testdata/return/fail_value_disallowed.carbon index 878202ff098ff..45d7ca47ea2dc 100644 --- a/toolchain/semantics/testdata/return/fail_value_disallowed.carbon +++ b/toolchain/semantics/testdata/return/fail_value_disallowed.carbon @@ -47,3 +47,13 @@ fn Main() { // CHECK:STDOUT: node+2, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc14: i32 = int_value 0 +// CHECK:STDOUT: return %.loc14 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/fail_value_missing.carbon b/toolchain/semantics/testdata/return/fail_value_missing.carbon index fa090751a3108..bde7eaa7095b7 100644 --- a/toolchain/semantics/testdata/return/fail_value_missing.carbon +++ b/toolchain/semantics/testdata/return/fail_value_missing.carbon @@ -41,3 +41,12 @@ fn Main() -> i32 { // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/missing_return_no_return_type.carbon b/toolchain/semantics/testdata/return/missing_return_no_return_type.carbon index fa5c134af8789..e7ffb47406a10 100644 --- a/toolchain/semantics/testdata/return/missing_return_no_return_type.carbon +++ b/toolchain/semantics/testdata/return/missing_return_no_return_type.carbon @@ -36,3 +36,12 @@ fn F() { // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/no_value.carbon b/toolchain/semantics/testdata/return/no_value.carbon index d9cebf08b9b31..0725b6f07f6a5 100644 --- a/toolchain/semantics/testdata/return/no_value.carbon +++ b/toolchain/semantics/testdata/return/no_value.carbon @@ -37,3 +37,12 @@ fn Main() { // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/struct.carbon b/toolchain/semantics/testdata/return/struct.carbon index 324c01dd1bff6..948535f90aed5 100644 --- a/toolchain/semantics/testdata/return/struct.carbon +++ b/toolchain/semantics/testdata/return/struct.carbon @@ -61,3 +61,16 @@ fn Main() -> {.a: i32} { // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_22: type = struct_type {.a: i32} +// CHECK:STDOUT: %.loc7_1 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> {.a: i32} { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8_16: i32 = int_value 3 +// CHECK:STDOUT: %.loc8_14: i32 = stub_reference %.loc8_16 +// CHECK:STDOUT: %.loc8_17: {.a: i32} = struct_value (%.loc8_14) +// CHECK:STDOUT: return %.loc8_17 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/tuple.carbon b/toolchain/semantics/testdata/return/tuple.carbon index f2e6fb0d03d28..cb52ebbc25e8d 100644 --- a/toolchain/semantics/testdata/return/tuple.carbon +++ b/toolchain/semantics/testdata/return/tuple.carbon @@ -79,3 +79,22 @@ fn Main() -> (i32, i32) { // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc8_15: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_20: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_23.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc8_23.2: (type, type) = tuple_value (%.loc8_15, %.loc8_20) +// CHECK:STDOUT: %.loc8_23.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %.loc8_1 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> (i32, i32) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc9_11.1: i32 = int_value 15 +// CHECK:STDOUT: %.loc9_11.2: i32 = stub_reference %.loc9_11.1 +// CHECK:STDOUT: %.loc9_15.1: i32 = int_value 35 +// CHECK:STDOUT: %.loc9_15.2: i32 = stub_reference %.loc9_15.1 +// CHECK:STDOUT: %.loc9_17: (i32, i32) = tuple_value (%.loc9_11.2, %.loc9_15.2) +// CHECK:STDOUT: return %.loc9_17 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/return/value.carbon b/toolchain/semantics/testdata/return/value.carbon index a1fed532930d7..1a6b4933ca3ab 100644 --- a/toolchain/semantics/testdata/return/value.carbon +++ b/toolchain/semantics/testdata/return/value.carbon @@ -41,3 +41,13 @@ fn Main() -> i32 { // CHECK:STDOUT: node+2, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() -> i32 { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc8: i32 = int_value 0 +// CHECK:STDOUT: return %.loc8 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/empty.carbon b/toolchain/semantics/testdata/struct/empty.carbon index 2b08d3f6fc9d8..844de18680840 100644 --- a/toolchain/semantics/testdata/struct/empty.carbon +++ b/toolchain/semantics/testdata/struct/empty.carbon @@ -51,3 +51,14 @@ var y: {} = x; // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9.1: type = struct_type {} +// CHECK:STDOUT: %.loc7_9.2: {} = struct_value () +// CHECK:STDOUT: %x: {} = var +// CHECK:STDOUT: %.loc7_14: {} = struct_value () +// CHECK:STDOUT: assign %x, %.loc7_14 +// CHECK:STDOUT: %.loc8: {} = struct_value () +// CHECK:STDOUT: %y: {} = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_access_into_invalid.carbon b/toolchain/semantics/testdata/struct/fail_access_into_invalid.carbon index 8445c6f96210b..f722190e7ea04 100644 --- a/toolchain/semantics/testdata/struct/fail_access_into_invalid.carbon +++ b/toolchain/semantics/testdata/struct/fail_access_into_invalid.carbon @@ -41,3 +41,12 @@ fn F() { a.b; } // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc11 = fn_decl @F +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_assign_empty.carbon b/toolchain/semantics/testdata/struct/fail_assign_empty.carbon index 7c3248f85e898..281bfd86a5b46 100644 --- a/toolchain/semantics/testdata/struct/fail_assign_empty.carbon +++ b/toolchain/semantics/testdata/struct/fail_assign_empty.carbon @@ -52,3 +52,11 @@ var x: {.a: i32} = {}; // CHECK:STDOUT: node+0, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_16: type = struct_type {.a: i32} +// CHECK:STDOUT: %x: {.a: i32} = var +// CHECK:STDOUT: %.loc10_21.1: type = struct_type {} +// CHECK:STDOUT: %.loc10_21.2: {} = struct_value () +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_assign_nested.carbon b/toolchain/semantics/testdata/struct/fail_assign_nested.carbon index 5f45eff62138c..dc1d228861fc2 100644 --- a/toolchain/semantics/testdata/struct/fail_assign_nested.carbon +++ b/toolchain/semantics/testdata/struct/fail_assign_nested.carbon @@ -68,3 +68,15 @@ var x: {.a: {}} = {.b = {}}; // CHECK:STDOUT: node+8, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_14.1: type = struct_type {} +// CHECK:STDOUT: %.loc10_14.2: {} = struct_value () +// CHECK:STDOUT: %.loc10_15: type = struct_type {.a: {}} +// CHECK:STDOUT: %x: {.a: {}} = var +// CHECK:STDOUT: %.loc10_26: {} = struct_value () +// CHECK:STDOUT: %.loc10_23: {} = stub_reference %.loc10_26 +// CHECK:STDOUT: %.loc10_27.1: type = struct_type {.b: {}} +// CHECK:STDOUT: %.loc10_27.2: {.b: {}} = struct_value (%.loc10_23) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_assign_to_empty.carbon b/toolchain/semantics/testdata/struct/fail_assign_to_empty.carbon index a29e7260c3d73..8916d3f829f5b 100644 --- a/toolchain/semantics/testdata/struct/fail_assign_to_empty.carbon +++ b/toolchain/semantics/testdata/struct/fail_assign_to_empty.carbon @@ -61,3 +61,14 @@ var x: {} = {.a = 1}; // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9.1: type = struct_type {} +// CHECK:STDOUT: %.loc10_9.2: {} = struct_value () +// CHECK:STDOUT: %x: {} = var +// CHECK:STDOUT: %.loc10_19: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_17: i32 = stub_reference %.loc10_19 +// CHECK:STDOUT: %.loc10_20.1: type = struct_type {.a: i32} +// CHECK:STDOUT: %.loc10_20.2: {.a: i32} = struct_value (%.loc10_17) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_field_name_mismatch.carbon b/toolchain/semantics/testdata/struct/fail_field_name_mismatch.carbon index 21f9428855c1d..3892f3b782363 100644 --- a/toolchain/semantics/testdata/struct/fail_field_name_mismatch.carbon +++ b/toolchain/semantics/testdata/struct/fail_field_name_mismatch.carbon @@ -65,3 +65,13 @@ var x: {.a: i32} = {.b = 1}; // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_16: type = struct_type {.a: i32} +// CHECK:STDOUT: %x: {.a: i32} = var +// CHECK:STDOUT: %.loc10_26: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_24: i32 = stub_reference %.loc10_26 +// CHECK:STDOUT: %.loc10_27.1: type = struct_type {.b: i32} +// CHECK:STDOUT: %.loc10_27.2: {.b: i32} = struct_value (%.loc10_24) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_field_type_mismatch.carbon b/toolchain/semantics/testdata/struct/fail_field_type_mismatch.carbon index 49023433f81d4..4ccebdd409170 100644 --- a/toolchain/semantics/testdata/struct/fail_field_type_mismatch.carbon +++ b/toolchain/semantics/testdata/struct/fail_field_type_mismatch.carbon @@ -66,3 +66,13 @@ var x: {.a: i32} = {.b = 1.0}; // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_16: type = struct_type {.a: i32} +// CHECK:STDOUT: %x: {.a: i32} = var +// CHECK:STDOUT: %.loc10_26: f64 = real_value 10e-1 +// CHECK:STDOUT: %.loc10_24: f64 = stub_reference %.loc10_26 +// CHECK:STDOUT: %.loc10_29.1: type = struct_type {.b: f64} +// CHECK:STDOUT: %.loc10_29.2: {.b: f64} = struct_value (%.loc10_24) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_member_access_type.carbon b/toolchain/semantics/testdata/struct/fail_member_access_type.carbon index 37b8b99d67973..6cdbbe70ec394 100644 --- a/toolchain/semantics/testdata/struct/fail_member_access_type.carbon +++ b/toolchain/semantics/testdata/struct/fail_member_access_type.carbon @@ -71,3 +71,14 @@ var y: i32 = x.b; // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_16: type = struct_type {.a: f64} +// CHECK:STDOUT: %x: {.a: f64} = var +// CHECK:STDOUT: %.loc7_26: f64 = real_value 40e-1 +// CHECK:STDOUT: %.loc7_24: f64 = stub_reference %.loc7_26 +// CHECK:STDOUT: %.loc7_29: {.a: f64} = struct_value (%.loc7_24) +// CHECK:STDOUT: assign %x, %.loc7_29 +// CHECK:STDOUT: %y: i32 = var +// CHECK:STDOUT: assign %y, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_non_member_access.carbon b/toolchain/semantics/testdata/struct/fail_non_member_access.carbon index b6f2c137d0f59..4e7bc1d86d46b 100644 --- a/toolchain/semantics/testdata/struct/fail_non_member_access.carbon +++ b/toolchain/semantics/testdata/struct/fail_non_member_access.carbon @@ -70,3 +70,14 @@ var y: i32 = x.b; // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_16: type = struct_type {.a: i32} +// CHECK:STDOUT: %x: {.a: i32} = var +// CHECK:STDOUT: %.loc7_26: i32 = int_value 4 +// CHECK:STDOUT: %.loc7_24: i32 = stub_reference %.loc7_26 +// CHECK:STDOUT: %.loc7_27: {.a: i32} = struct_value (%.loc7_24) +// CHECK:STDOUT: assign %x, %.loc7_27 +// CHECK:STDOUT: %y: i32 = var +// CHECK:STDOUT: assign %y, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_too_few_values.carbon b/toolchain/semantics/testdata/struct/fail_too_few_values.carbon index d6f005b32dfdd..8ba1773fce4fe 100644 --- a/toolchain/semantics/testdata/struct/fail_too_few_values.carbon +++ b/toolchain/semantics/testdata/struct/fail_too_few_values.carbon @@ -68,3 +68,13 @@ var x: {.a: i32, .b: i32} = {.a = 1}; // CHECK:STDOUT: node+7, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_25: type = struct_type {.a: i32, .b: i32} +// CHECK:STDOUT: %x: {.a: i32, .b: i32} = var +// CHECK:STDOUT: %.loc10_35: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_33: i32 = stub_reference %.loc10_35 +// CHECK:STDOUT: %.loc10_36.1: type = struct_type {.a: i32} +// CHECK:STDOUT: %.loc10_36.2: {.a: i32} = struct_value (%.loc10_33) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_type_assign.carbon b/toolchain/semantics/testdata/struct/fail_type_assign.carbon index febc5c7a0fe16..e6f41e8cf2670 100644 --- a/toolchain/semantics/testdata/struct/fail_type_assign.carbon +++ b/toolchain/semantics/testdata/struct/fail_type_assign.carbon @@ -52,3 +52,9 @@ var x: {.a: i32} = {.a: i32}; // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10: type = struct_type {.a: i32} +// CHECK:STDOUT: %x: {.a: i32} = var +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/fail_value_as_type.carbon b/toolchain/semantics/testdata/struct/fail_value_as_type.carbon index 603493c236b3d..98afdf0be4f2e 100644 --- a/toolchain/semantics/testdata/struct/fail_value_as_type.carbon +++ b/toolchain/semantics/testdata/struct/fail_value_as_type.carbon @@ -54,3 +54,11 @@ var x: {.a = 1}; // CHECK:STDOUT: node+2, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_14: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_12: i32 = stub_reference %.loc10_14 +// CHECK:STDOUT: %.loc10_15.1: type = struct_type {.a: i32} +// CHECK:STDOUT: %.loc10_15.2: {.a: i32} = struct_value (%.loc10_12) +// CHECK:STDOUT: %x: = var +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/member_access.carbon b/toolchain/semantics/testdata/struct/member_access.carbon index c77f047d1662c..26ac8253cf261 100644 --- a/toolchain/semantics/testdata/struct/member_access.carbon +++ b/toolchain/semantics/testdata/struct/member_access.carbon @@ -89,3 +89,19 @@ var z: i32 = y; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_25: type = struct_type {.a: f64, .b: i32} +// CHECK:STDOUT: %x: {.a: f64, .b: i32} = var +// CHECK:STDOUT: %.loc7_35: f64 = real_value 0e-1 +// CHECK:STDOUT: %.loc7_33: f64 = stub_reference %.loc7_35 +// CHECK:STDOUT: %.loc7_45: i32 = int_value 1 +// CHECK:STDOUT: %.loc7_43: i32 = stub_reference %.loc7_45 +// CHECK:STDOUT: %.loc7_46: {.a: f64, .b: i32} = struct_value (%.loc7_33, %.loc7_43) +// CHECK:STDOUT: assign %x, %.loc7_46 +// CHECK:STDOUT: %y: i32 = var +// CHECK:STDOUT: %.loc8: i32 = struct_access %x, member1 +// CHECK:STDOUT: assign %y, %.loc8 +// CHECK:STDOUT: %z: i32 = var +// CHECK:STDOUT: assign %z, %y +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/one_entry.carbon b/toolchain/semantics/testdata/struct/one_entry.carbon index d0ecffba32286..b834c2260ad9b 100644 --- a/toolchain/semantics/testdata/struct/one_entry.carbon +++ b/toolchain/semantics/testdata/struct/one_entry.carbon @@ -71,3 +71,14 @@ var y: {.a: i32} = x; // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_16: type = struct_type {.a: i32} +// CHECK:STDOUT: %x: {.a: i32} = var +// CHECK:STDOUT: %.loc7_26: i32 = int_value 4 +// CHECK:STDOUT: %.loc7_24: i32 = stub_reference %.loc7_26 +// CHECK:STDOUT: %.loc7_27: {.a: i32} = struct_value (%.loc7_24) +// CHECK:STDOUT: assign %x, %.loc7_27 +// CHECK:STDOUT: %y: {.a: i32} = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/tuple_as_element.carbon b/toolchain/semantics/testdata/struct/tuple_as_element.carbon index fafa36b008a97..979b65fca0376 100644 --- a/toolchain/semantics/testdata/struct/tuple_as_element.carbon +++ b/toolchain/semantics/testdata/struct/tuple_as_element.carbon @@ -119,3 +119,24 @@ var y: {.a: i32, .b: (i32,)} = x; // CHECK:STDOUT: node+20, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_23: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_27.1: type = tuple_type (type) +// CHECK:STDOUT: %.loc7_27.2: (type,) = tuple_value (%.loc7_23) +// CHECK:STDOUT: %.loc7_27.3: type = tuple_type (i32) +// CHECK:STDOUT: %.loc7_28: type = struct_type {.a: i32, .b: (i32,)} +// CHECK:STDOUT: %x: {.a: i32, .b: (i32,)} = var +// CHECK:STDOUT: %.loc7_38: i32 = int_value 1 +// CHECK:STDOUT: %.loc7_36: i32 = stub_reference %.loc7_38 +// CHECK:STDOUT: %.loc7_47.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc7_47.2: i32 = stub_reference %.loc7_47.1 +// CHECK:STDOUT: %.loc7_49: (i32,) = tuple_value (%.loc7_47.2) +// CHECK:STDOUT: %.loc7_44: (i32,) = stub_reference %.loc7_49 +// CHECK:STDOUT: %.loc7_50: {.a: i32, .b: (i32,)} = struct_value (%.loc7_36, %.loc7_44) +// CHECK:STDOUT: assign %x, %.loc7_50 +// CHECK:STDOUT: %.loc8_23: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_27: (type,) = tuple_value (%.loc8_23) +// CHECK:STDOUT: %y: {.a: i32, .b: (i32,)} = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/struct/two_entries.carbon b/toolchain/semantics/testdata/struct/two_entries.carbon index 012d1b19501e9..3dd084a90534e 100644 --- a/toolchain/semantics/testdata/struct/two_entries.carbon +++ b/toolchain/semantics/testdata/struct/two_entries.carbon @@ -86,3 +86,16 @@ var y: {.a: i32, .b: i32} = x; // CHECK:STDOUT: node+14, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_25: type = struct_type {.a: i32, .b: i32} +// CHECK:STDOUT: %x: {.a: i32, .b: i32} = var +// CHECK:STDOUT: %.loc7_35: i32 = int_value 1 +// CHECK:STDOUT: %.loc7_33: i32 = stub_reference %.loc7_35 +// CHECK:STDOUT: %.loc7_43: i32 = int_value 2 +// CHECK:STDOUT: %.loc7_41: i32 = stub_reference %.loc7_43 +// CHECK:STDOUT: %.loc7_44: {.a: i32, .b: i32} = struct_value (%.loc7_33, %.loc7_41) +// CHECK:STDOUT: assign %x, %.loc7_44 +// CHECK:STDOUT: %y: {.a: i32, .b: i32} = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/empty.carbon b/toolchain/semantics/testdata/tuples/empty.carbon index 90f1529a17083..18ee2c5bf282d 100644 --- a/toolchain/semantics/testdata/tuples/empty.carbon +++ b/toolchain/semantics/testdata/tuples/empty.carbon @@ -53,3 +53,14 @@ var y: () = x; // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9.1: type = tuple_type () +// CHECK:STDOUT: %.loc7_9.2: () = tuple_value () +// CHECK:STDOUT: %x: () = var +// CHECK:STDOUT: %.loc7_14: () = tuple_value () +// CHECK:STDOUT: assign %x, %.loc7_14 +// CHECK:STDOUT: %.loc8: () = tuple_value () +// CHECK:STDOUT: %y: () = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/fail_assign_empty.carbon b/toolchain/semantics/testdata/tuples/fail_assign_empty.carbon index d2e868288702e..897bc026bb458 100644 --- a/toolchain/semantics/testdata/tuples/fail_assign_empty.carbon +++ b/toolchain/semantics/testdata/tuples/fail_assign_empty.carbon @@ -64,3 +64,14 @@ var x: (i32,) = (); // CHECK:STDOUT: node+0, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_13.1: type = tuple_type (type) +// CHECK:STDOUT: %.loc10_13.2: (type,) = tuple_value (%.loc10_9) +// CHECK:STDOUT: %.loc10_13.3: type = tuple_type (i32) +// CHECK:STDOUT: %x: (i32,) = var +// CHECK:STDOUT: %.loc10_18.1: type = tuple_type () +// CHECK:STDOUT: %.loc10_18.2: () = tuple_value () +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/fail_assign_nested.carbon b/toolchain/semantics/testdata/tuples/fail_assign_nested.carbon index 4cd5145c9c7c9..5ef58a413bf15 100644 --- a/toolchain/semantics/testdata/tuples/fail_assign_nested.carbon +++ b/toolchain/semantics/testdata/tuples/fail_assign_nested.carbon @@ -165,3 +165,40 @@ var x: ((i32, i32), (i32, i32)) = ((1, 2, 3), (4, 5, 6)); // CHECK:STDOUT: node+29, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_10: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_15: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_18.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc10_18.2: (type, type) = tuple_value (%.loc10_10, %.loc10_15) +// CHECK:STDOUT: %.loc10_18.3: (type, type) = stub_reference %.loc10_18.2 +// CHECK:STDOUT: %.loc10_22: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_27: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_30.1: (type, type) = tuple_value (%.loc10_22, %.loc10_27) +// CHECK:STDOUT: %.loc10_30.2: (type, type) = stub_reference %.loc10_30.1 +// CHECK:STDOUT: %.loc10_31.1: type = tuple_type ((type, type), (type, type)) +// CHECK:STDOUT: %.loc10_31.2: ((type, type), (type, type)) = tuple_value (%.loc10_18.3, %.loc10_30.2) +// CHECK:STDOUT: %.loc10_18.4: type = tuple_type (i32, i32) +// CHECK:STDOUT: %.loc10_31.3: type = tuple_type ((i32, i32), (i32, i32)) +// CHECK:STDOUT: %x: ((i32, i32), (i32, i32)) = var +// CHECK:STDOUT: %.loc10_37.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_37.2: i32 = stub_reference %.loc10_37.1 +// CHECK:STDOUT: %.loc10_40.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc10_40.2: i32 = stub_reference %.loc10_40.1 +// CHECK:STDOUT: %.loc10_43.1: i32 = int_value 3 +// CHECK:STDOUT: %.loc10_43.2: i32 = stub_reference %.loc10_43.1 +// CHECK:STDOUT: %.loc10_44.1: type = tuple_type (i32, i32, i32) +// CHECK:STDOUT: %.loc10_44.2: (i32, i32, i32) = tuple_value (%.loc10_37.2, %.loc10_40.2, %.loc10_43.2) +// CHECK:STDOUT: %.loc10_44.3: (i32, i32, i32) = stub_reference %.loc10_44.2 +// CHECK:STDOUT: %.loc10_48.1: i32 = int_value 4 +// CHECK:STDOUT: %.loc10_48.2: i32 = stub_reference %.loc10_48.1 +// CHECK:STDOUT: %.loc10_51.1: i32 = int_value 5 +// CHECK:STDOUT: %.loc10_51.2: i32 = stub_reference %.loc10_51.1 +// CHECK:STDOUT: %.loc10_54.1: i32 = int_value 6 +// CHECK:STDOUT: %.loc10_54.2: i32 = stub_reference %.loc10_54.1 +// CHECK:STDOUT: %.loc10_55.1: (i32, i32, i32) = tuple_value (%.loc10_48.2, %.loc10_51.2, %.loc10_54.2) +// CHECK:STDOUT: %.loc10_55.2: (i32, i32, i32) = stub_reference %.loc10_55.1 +// CHECK:STDOUT: %.loc10_56.1: type = tuple_type ((i32, i32, i32), (i32, i32, i32)) +// CHECK:STDOUT: %.loc10_56.2: ((i32, i32, i32), (i32, i32, i32)) = tuple_value (%.loc10_44.3, %.loc10_55.2) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/fail_assign_to_empty.carbon b/toolchain/semantics/testdata/tuples/fail_assign_to_empty.carbon index 2c1fae398d8fd..82c81fdf4cdef 100644 --- a/toolchain/semantics/testdata/tuples/fail_assign_to_empty.carbon +++ b/toolchain/semantics/testdata/tuples/fail_assign_to_empty.carbon @@ -48,3 +48,11 @@ var x: () = (66); // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9.1: type = tuple_type () +// CHECK:STDOUT: %.loc10_9.2: () = tuple_value () +// CHECK:STDOUT: %x: () = var +// CHECK:STDOUT: %.loc10_14: i32 = int_value 66 +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/fail_element_type_mismatch.carbon b/toolchain/semantics/testdata/tuples/fail_element_type_mismatch.carbon index 8ae0662075ffd..9743a2dd1c08f 100644 --- a/toolchain/semantics/testdata/tuples/fail_element_type_mismatch.carbon +++ b/toolchain/semantics/testdata/tuples/fail_element_type_mismatch.carbon @@ -86,3 +86,19 @@ var x: (i32, i32) = (2, 65.89); // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_14: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_17.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc10_17.2: (type, type) = tuple_value (%.loc10_9, %.loc10_14) +// CHECK:STDOUT: %.loc10_17.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %x: (i32, i32) = var +// CHECK:STDOUT: %.loc10_22.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc10_22.2: i32 = stub_reference %.loc10_22.1 +// CHECK:STDOUT: %.loc10_25.1: f64 = real_value 6589e-2 +// CHECK:STDOUT: %.loc10_25.2: f64 = stub_reference %.loc10_25.1 +// CHECK:STDOUT: %.loc10_30.1: type = tuple_type (i32, f64) +// CHECK:STDOUT: %.loc10_30.2: (i32, f64) = tuple_value (%.loc10_22.2, %.loc10_25.2) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/fail_too_few_element.carbon b/toolchain/semantics/testdata/tuples/fail_too_few_element.carbon index 427edc0c27f6d..adc63ffd1dc5d 100644 --- a/toolchain/semantics/testdata/tuples/fail_too_few_element.carbon +++ b/toolchain/semantics/testdata/tuples/fail_too_few_element.carbon @@ -78,3 +78,17 @@ var x: (i32, i32) = (2, ); // CHECK:STDOUT: node+8, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_14: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_17.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc10_17.2: (type, type) = tuple_value (%.loc10_9, %.loc10_14) +// CHECK:STDOUT: %.loc10_17.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %x: (i32, i32) = var +// CHECK:STDOUT: %.loc10_22.1: i32 = int_value 2 +// CHECK:STDOUT: %.loc10_22.2: i32 = stub_reference %.loc10_22.1 +// CHECK:STDOUT: %.loc10_25.1: type = tuple_type (i32) +// CHECK:STDOUT: %.loc10_25.2: (i32,) = tuple_value (%.loc10_22.2) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/fail_type_assign.carbon b/toolchain/semantics/testdata/tuples/fail_type_assign.carbon index f2f70bc1d06ef..1ae3ac42ad377 100644 --- a/toolchain/semantics/testdata/tuples/fail_type_assign.carbon +++ b/toolchain/semantics/testdata/tuples/fail_type_assign.carbon @@ -64,3 +64,14 @@ var x: (i32, ) = (i32, ); // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_14.1: type = tuple_type (type) +// CHECK:STDOUT: %.loc10_14.2: (type,) = tuple_value (%.loc10_9) +// CHECK:STDOUT: %.loc10_14.3: type = tuple_type (i32) +// CHECK:STDOUT: %x: (i32,) = var +// CHECK:STDOUT: %.loc10_19: type = stub_reference i32 +// CHECK:STDOUT: %.loc10_24: (type,) = tuple_value (%.loc10_19) +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/fail_value_as_type.carbon b/toolchain/semantics/testdata/tuples/fail_value_as_type.carbon index 72dda97e25428..835a4867d917a 100644 --- a/toolchain/semantics/testdata/tuples/fail_value_as_type.carbon +++ b/toolchain/semantics/testdata/tuples/fail_value_as_type.carbon @@ -58,3 +58,12 @@ var x: (1, ); // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9.1: i32 = int_value 1 +// CHECK:STDOUT: %.loc10_9.2: i32 = stub_reference %.loc10_9.1 +// CHECK:STDOUT: %.loc10_12.1: type = tuple_type (i32) +// CHECK:STDOUT: %.loc10_12.2: (i32,) = tuple_value (%.loc10_9.2) +// CHECK:STDOUT: %.loc10_12.3: type = tuple_type () +// CHECK:STDOUT: %x: (,) = var +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/nested_tuple.carbon b/toolchain/semantics/testdata/tuples/nested_tuple.carbon index 159ab33a404c5..7d3a016c98549 100644 --- a/toolchain/semantics/testdata/tuples/nested_tuple.carbon +++ b/toolchain/semantics/testdata/tuples/nested_tuple.carbon @@ -112,3 +112,27 @@ var x: ((i32, i32), i32) = ((12, 76), 6); // CHECK:STDOUT: node+19, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_10: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_15: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_18.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc7_18.2: (type, type) = tuple_value (%.loc7_10, %.loc7_15) +// CHECK:STDOUT: %.loc7_18.3: (type, type) = stub_reference %.loc7_18.2 +// CHECK:STDOUT: %.loc7_21: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_24.1: type = tuple_type ((type, type), type) +// CHECK:STDOUT: %.loc7_24.2: ((type, type), type) = tuple_value (%.loc7_18.3, %.loc7_21) +// CHECK:STDOUT: %.loc7_18.4: type = tuple_type (i32, i32) +// CHECK:STDOUT: %.loc7_24.3: type = tuple_type ((i32, i32), i32) +// CHECK:STDOUT: %x: ((i32, i32), i32) = var +// CHECK:STDOUT: %.loc7_30.1: i32 = int_value 12 +// CHECK:STDOUT: %.loc7_30.2: i32 = stub_reference %.loc7_30.1 +// CHECK:STDOUT: %.loc7_34.1: i32 = int_value 76 +// CHECK:STDOUT: %.loc7_34.2: i32 = stub_reference %.loc7_34.1 +// CHECK:STDOUT: %.loc7_36.1: (i32, i32) = tuple_value (%.loc7_30.2, %.loc7_34.2) +// CHECK:STDOUT: %.loc7_36.2: (i32, i32) = stub_reference %.loc7_36.1 +// CHECK:STDOUT: %.loc7_39.1: i32 = int_value 6 +// CHECK:STDOUT: %.loc7_39.2: i32 = stub_reference %.loc7_39.1 +// CHECK:STDOUT: %.loc7_40: ((i32, i32), i32) = tuple_value (%.loc7_36.2, %.loc7_39.2) +// CHECK:STDOUT: assign %x, %.loc7_40 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/one_element.carbon b/toolchain/semantics/testdata/tuples/one_element.carbon index de2802084d366..6c9deac243fd5 100644 --- a/toolchain/semantics/testdata/tuples/one_element.carbon +++ b/toolchain/semantics/testdata/tuples/one_element.carbon @@ -79,3 +79,19 @@ var y: (i32,) = x; // CHECK:STDOUT: node+10, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_13.1: type = tuple_type (type) +// CHECK:STDOUT: %.loc7_13.2: (type,) = tuple_value (%.loc7_9) +// CHECK:STDOUT: %.loc7_13.3: type = tuple_type (i32) +// CHECK:STDOUT: %x: (i32,) = var +// CHECK:STDOUT: %.loc7_18.1: i32 = int_value 4 +// CHECK:STDOUT: %.loc7_18.2: i32 = stub_reference %.loc7_18.1 +// CHECK:STDOUT: %.loc7_20: (i32,) = tuple_value (%.loc7_18.2) +// CHECK:STDOUT: assign %x, %.loc7_20 +// CHECK:STDOUT: %.loc8_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_13: (type,) = tuple_value (%.loc8_9) +// CHECK:STDOUT: %y: (i32,) = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/tuples/two_elements.carbon b/toolchain/semantics/testdata/tuples/two_elements.carbon index 8dd1fa9763d50..34210600e934d 100644 --- a/toolchain/semantics/testdata/tuples/two_elements.carbon +++ b/toolchain/semantics/testdata/tuples/two_elements.carbon @@ -93,3 +93,23 @@ var y: (i32, i32) = x; // CHECK:STDOUT: node+14, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_14: type = stub_reference i32 +// CHECK:STDOUT: %.loc7_17.1: type = tuple_type (type, type) +// CHECK:STDOUT: %.loc7_17.2: (type, type) = tuple_value (%.loc7_9, %.loc7_14) +// CHECK:STDOUT: %.loc7_17.3: type = tuple_type (i32, i32) +// CHECK:STDOUT: %x: (i32, i32) = var +// CHECK:STDOUT: %.loc7_22.1: i32 = int_value 4 +// CHECK:STDOUT: %.loc7_22.2: i32 = stub_reference %.loc7_22.1 +// CHECK:STDOUT: %.loc7_25.1: i32 = int_value 102 +// CHECK:STDOUT: %.loc7_25.2: i32 = stub_reference %.loc7_25.1 +// CHECK:STDOUT: %.loc7_28: (i32, i32) = tuple_value (%.loc7_22.2, %.loc7_25.2) +// CHECK:STDOUT: assign %x, %.loc7_28 +// CHECK:STDOUT: %.loc8_9: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_14: type = stub_reference i32 +// CHECK:STDOUT: %.loc8_17: (type, type) = tuple_value (%.loc8_9, %.loc8_14) +// CHECK:STDOUT: %y: (i32, i32) = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/decl.carbon b/toolchain/semantics/testdata/var/decl.carbon index 14f7cff7f4d33..c5b213a4b85b0 100644 --- a/toolchain/semantics/testdata/var/decl.carbon +++ b/toolchain/semantics/testdata/var/decl.carbon @@ -43,3 +43,13 @@ fn Main() { // CHECK:STDOUT: node+3, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/decl_with_init.carbon b/toolchain/semantics/testdata/var/decl_with_init.carbon index 9d2796f2591aa..a98f55e643c69 100644 --- a/toolchain/semantics/testdata/var/decl_with_init.carbon +++ b/toolchain/semantics/testdata/var/decl_with_init.carbon @@ -48,3 +48,15 @@ fn Main() { // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %.loc8: i32 = int_value 0 +// CHECK:STDOUT: assign %x, %.loc8 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/fail_duplicate_decl.carbon b/toolchain/semantics/testdata/var/fail_duplicate_decl.carbon index 381708f10d76e..4c74c09f8ae49 100644 --- a/toolchain/semantics/testdata/var/fail_duplicate_decl.carbon +++ b/toolchain/semantics/testdata/var/fail_duplicate_decl.carbon @@ -65,3 +65,18 @@ fn Main() { // CHECK:STDOUT: node+9, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc8 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x.loc9: i32 = var +// CHECK:STDOUT: %.loc9: i32 = int_value 0 +// CHECK:STDOUT: assign %x.loc9, %.loc9 +// CHECK:STDOUT: %x.loc16: i32 = var +// CHECK:STDOUT: %.loc16: i32 = int_value 0 +// CHECK:STDOUT: assign %x.loc16, %.loc16 +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/fail_init_type_mismatch.carbon b/toolchain/semantics/testdata/var/fail_init_type_mismatch.carbon index bdc0d984cb17e..e13537c534cc1 100644 --- a/toolchain/semantics/testdata/var/fail_init_type_mismatch.carbon +++ b/toolchain/semantics/testdata/var/fail_init_type_mismatch.carbon @@ -52,3 +52,15 @@ fn Main() { // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %.loc11: f64 = real_value 10e-1 +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/fail_init_with_self.carbon b/toolchain/semantics/testdata/var/fail_init_with_self.carbon index 0999c0d48238c..71b38ba05f23f 100644 --- a/toolchain/semantics/testdata/var/fail_init_with_self.carbon +++ b/toolchain/semantics/testdata/var/fail_init_with_self.carbon @@ -48,3 +48,14 @@ fn Main() { // CHECK:STDOUT: node+4, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/fail_lookup_outside_scope.carbon b/toolchain/semantics/testdata/var/fail_lookup_outside_scope.carbon index cdb100289a7d4..5d4630c3eb40f 100644 --- a/toolchain/semantics/testdata/var/fail_lookup_outside_scope.carbon +++ b/toolchain/semantics/testdata/var/fail_lookup_outside_scope.carbon @@ -55,3 +55,15 @@ var y: i32 = x; // CHECK:STDOUT: node+3, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: %y: i32 = var +// CHECK:STDOUT: assign %y, +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/fail_storage_is_literal.carbon b/toolchain/semantics/testdata/var/fail_storage_is_literal.carbon index 1b385ab60e6c5..c2e264d973fb8 100644 --- a/toolchain/semantics/testdata/var/fail_storage_is_literal.carbon +++ b/toolchain/semantics/testdata/var/fail_storage_is_literal.carbon @@ -54,3 +54,16 @@ fn Main() { // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %.loc11_10: i32 = int_value 1 +// CHECK:STDOUT: %x: = var +// CHECK:STDOUT: %.loc11_14: i32 = int_value 1 +// CHECK:STDOUT: assign %x, +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/global_decl.carbon b/toolchain/semantics/testdata/var/global_decl.carbon index 4de7053ae2a98..f2d97a0c218cc 100644 --- a/toolchain/semantics/testdata/var/global_decl.carbon +++ b/toolchain/semantics/testdata/var/global_decl.carbon @@ -33,3 +33,7 @@ var x: i32; // CHECK:STDOUT: node+1, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/global_decl_with_init.carbon b/toolchain/semantics/testdata/var/global_decl_with_init.carbon index a8b4160c859cb..e7d33c34a6979 100644 --- a/toolchain/semantics/testdata/var/global_decl_with_init.carbon +++ b/toolchain/semantics/testdata/var/global_decl_with_init.carbon @@ -38,3 +38,9 @@ var x: i32 = 0; // CHECK:STDOUT: node+3, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %.loc7: i32 = int_value 0 +// CHECK:STDOUT: assign %x, %.loc7 +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/global_lookup.carbon b/toolchain/semantics/testdata/var/global_lookup.carbon index e93765fae5ac2..f4fb61a57239b 100644 --- a/toolchain/semantics/testdata/var/global_lookup.carbon +++ b/toolchain/semantics/testdata/var/global_lookup.carbon @@ -46,3 +46,11 @@ var y: i32 = x; // CHECK:STDOUT: node+6, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %.loc7: i32 = int_value 0 +// CHECK:STDOUT: assign %x, %.loc7 +// CHECK:STDOUT: %y: i32 = var +// CHECK:STDOUT: assign %y, %x +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/global_lookup_in_scope.carbon b/toolchain/semantics/testdata/var/global_lookup_in_scope.carbon index de84f44bb8d9d..d6f7b82770e53 100644 --- a/toolchain/semantics/testdata/var/global_lookup_in_scope.carbon +++ b/toolchain/semantics/testdata/var/global_lookup_in_scope.carbon @@ -57,3 +57,17 @@ fn Main() { // CHECK:STDOUT: node+8, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %.loc7: i32 = int_value 0 +// CHECK:STDOUT: assign %x, %.loc7 +// CHECK:STDOUT: %.loc9 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %y: i32 = var +// CHECK:STDOUT: assign %y, package.%x +// CHECK:STDOUT: return +// CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/var/lookup.carbon b/toolchain/semantics/testdata/var/lookup.carbon index 2449ee4d7eb78..179a45cef43eb 100644 --- a/toolchain/semantics/testdata/var/lookup.carbon +++ b/toolchain/semantics/testdata/var/lookup.carbon @@ -49,3 +49,15 @@ fn Main() { // CHECK:STDOUT: node+5, // CHECK:STDOUT: ], // CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc7 = fn_decl @Main +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Main() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %x: i32 = var +// CHECK:STDOUT: %.loc8: i32 = int_value 0 +// CHECK:STDOUT: assign %x, %.loc8 +// CHECK:STDOUT: return +// CHECK:STDOUT: }