mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Export Carbon global variables and static vars to C++ (#7298)
Add `ExportVarToCpp`. This checks the `clang_decls` mapping and returns an existing decl if found. Otherwise, it creates a new `VarDecl` and adds it to the `clang_decls` mapping. When lowering, in `FileContext::BuildGlobalVariableDecl`, the `clang_decls` mapping is used to lookup an existing `llvm::GlobalVariable` for the instruction. If found, use that rather than creating a new one to avoid an unwanted second definition in the llvm IR.
This commit is contained in:
@@ -435,6 +435,10 @@ auto CarbonExternalASTSource::MapInstIdToClangDeclOrType(LookupResult lookup)
|
||||
case CARBON_KIND(SemIR::FieldDecl field_decl): {
|
||||
return ExportFieldToCpp(*context_, target_inst_id, field_decl);
|
||||
}
|
||||
case CARBON_KIND(SemIR::VarStorage var_storage): {
|
||||
return ExportVarToCpp(*context_, SemIR::LocId(target_inst_id),
|
||||
var_storage);
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user