[clang] [CIR] Introduce LocalInitOp, & lower static locals (PR #193576)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 22 23:57:50 PDT 2026


================
@@ -371,6 +371,45 @@ LogicalResult cir::BreakOp::verify() {
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// LocalInitOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult cir::LocalInitOp::verify() {
+  if (!getOperation()->getParentOfType<FuncOp>())
+    return emitOpError("must be inside of a function");
+
+  if (getStaticLocal() && getTls())
+    return emitOpError("cannot be both static and thread local");
+
+  if (!getStaticLocal() && !getTls())
+    return emitOpError("must be one of static and thread local");
+
+  return success();
+}
+
+LogicalResult
+cir::LocalInitOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
+  mlir::Operation *op =
+      symbolTable.lookupNearestSymbolFrom(*this, getGlobalNameAttr());
+  if (op == nullptr || !isa<GlobalOp>(op))
----------------
xlauko wrote:

```suggestion
  cir::GlobalOp global = getReferencedGlobal(symbolTable);
  if (!global)
```

https://github.com/llvm/llvm-project/pull/193576


More information about the cfe-commits mailing list