clang 23.0.0git
CIRGenDeclCXX.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code dealing with code generation of C++ declarations
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenCXXABI.h"
14#include "CIRGenFunction.h"
15#include "CIRGenModule.h"
16#include "clang/AST/Attr.h"
17#include "clang/AST/Mangle.h"
20
21using namespace clang;
22using namespace clang::CIRGen;
23
25 cir::GlobalOp globalOp,
26 bool performInit) {
27 // If we've been asked to forbid guard variables, emit an error now.
28 // This diagnostic is hard-coded for Darwin's use case; we can find
29 // better phrasing if someone else needs it.
30 if (cgm.getCodeGenOpts().ForbidGuardVariables)
31 cgm.error(varDecl.getLocation(), "guard variables are forbidden");
32
33 // Compute the mangled guard variable name and set the static_local attribute
34 // BEFORE emitting initialization. This ensures that GetGlobalOps created
35 // during initialization (e.g., in the ctor region) will see the attribute
36 // and be marked with static_local accordingly.
37 llvm::SmallString<256> guardName;
38 {
39 llvm::raw_svector_ostream out(guardName);
40 cgm.getCXXABI().getMangleContext().mangleStaticGuardVariable(&varDecl, out);
41 }
42
43 // Mark the global as static local with the guard name. The emission of the
44 // guard/acquire is done during LoweringPrepare.
45 auto guardAttr = mlir::StringAttr::get(&cgm.getMLIRContext(), guardName);
46 globalOp.setStaticLocalGuardAttr(
47 cir::StaticLocalGuardAttr::get(&cgm.getMLIRContext(), guardAttr));
48
49 // Emit the initializer and add a global destructor if appropriate.
50 cgm.emitCXXGlobalVarDeclInit(&varDecl, globalOp, performInit);
51}
52
54 cir::GlobalOp addr,
55 bool performInit) {
57
59
60 emitCXXGlobalVarDeclInit(vd, addr, performInit);
61}
Defines the clang::LangOptions interface.
void emitCXXGuardedInit(const VarDecl &varDecl, cir::GlobalOp globalOp, bool performInit)
Emit a guarded initializer for a static local variable or a static data member of a class template in...
void emitCXXGlobalVarDeclInit(const VarDecl *varDecl, cir::GlobalOp addr, bool performInit)
Emit the function that initializes the specified global.
void emitCXXGlobalVarDeclInitFunc(const VarDecl *vd, cir::GlobalOp addr, bool performInit)
Represents a variable declaration or definition.
Definition Decl.h:926
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
The JSON file list parser is used to communicate input to InstallAPI.
static bool deferredCXXGlobalInit()
static bool cudaSupport()