[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread LLVM Continuous Integration via cfe-commits
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux-bootstrap-msan` running on `sanitizer-buildbot6` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/164/builds/9589 Here is the releva

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor closed https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/138222 >From b3ae2d60a178f3c5bb8950804041386a667abc6e Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Tue, 29 Apr 2025 15:47:01 -0700 Subject: [PATCH 1/4] [CIR] Refactor global variable emission and initialization

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -365,46 +406,108 @@ mlir::Value CIRGenModule::getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty, void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative) { const QualType astTy = vd->getType(); - c

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -90,8 +90,100 @@ class ConstExprEmitter } mlir::Attribute VisitCastExpr(CastExpr *e, QualType destType) { -cgm.errorNYI(e->getBeginLoc(), "ConstExprEmitter::VisitCastExpr"); -return {}; +if (const auto *ece = dyn_cast(e)) + cgm.errorNYI(e->getBeginLoc()

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -31,6 +31,15 @@ class ConstantEmitter { private: bool abstract = false; + /// Whether non-abstract components of the emitter have been initialized. + bool initializedNonAbstract = false; andykaylor wrote: Yes, these are just for debugging. Wrapping the

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -365,46 +406,108 @@ mlir::Value CIRGenModule::getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty, void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative) { const QualType astTy = vd->getType(); - c

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -118,7 +210,26 @@ class ConstExprEmitter } mlir::Attribute VisitInitListExpr(InitListExpr *ile, QualType t) { -cgm.errorNYI(ile->getBeginLoc(), "ConstExprEmitter::VisitInitListExpr"); +if (ile->isTransparent()) + return Visit(ile->getInit(0), t); + +if

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Morris Hafner via cfe-commits
https://github.com/mmha commented: Mostly a few nits. https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Morris Hafner via cfe-commits
@@ -365,46 +406,108 @@ mlir::Value CIRGenModule::getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty, void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative) { const QualType astTy = vd->getType(); - c

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Morris Hafner via cfe-commits
@@ -118,7 +210,26 @@ class ConstExprEmitter } mlir::Attribute VisitInitListExpr(InitListExpr *ile, QualType t) { -cgm.errorNYI(ile->getBeginLoc(), "ConstExprEmitter::VisitInitListExpr"); +if (ile->isTransparent()) + return Visit(ile->getInit(0), t); + +if

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Morris Hafner via cfe-commits
@@ -365,46 +406,108 @@ mlir::Value CIRGenModule::getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty, void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative) { const QualType astTy = vd->getType(); - c

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Morris Hafner via cfe-commits
@@ -31,6 +31,15 @@ class ConstantEmitter { private: bool abstract = false; + /// Whether non-abstract components of the emitter have been initialized. + bool initializedNonAbstract = false; mmha wrote: Is this just for sanity checking? Should this be wrap

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Morris Hafner via cfe-commits
@@ -90,8 +90,100 @@ class ConstExprEmitter } mlir::Attribute VisitCastExpr(CastExpr *e, QualType destType) { -cgm.errorNYI(e->getBeginLoc(), "ConstExprEmitter::VisitCastExpr"); -return {}; +if (const auto *ece = dyn_cast(e)) + cgm.errorNYI(e->getBeginLoc()

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Morris Hafner via cfe-commits
https://github.com/mmha edited https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/138222 >From b3ae2d60a178f3c5bb8950804041386a667abc6e Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Tue, 29 Apr 2025 15:47:01 -0700 Subject: [PATCH 1/3] [CIR] Refactor global variable emission and initialization

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Amr Hesham via cfe-commits
@@ -46,6 +55,14 @@ class ConstantEmitter { ConstantEmitter(const ConstantEmitter &other) = delete; ConstantEmitter &operator=(const ConstantEmitter &other) = delete; + ~ConstantEmitter(); + + /// Try to emit the initiaizer of the given declaration as an abstract

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Amr Hesham via cfe-commits
https://github.com/AmrDeveloper approved this pull request. https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -269,6 +269,40 @@ mlir::Operation *CIRGenModule::getGlobalValue(StringRef name) { return mlir::SymbolTable::lookupSymbolIn(theModule, name); } +cir::GlobalOp CIRGenModule::createGlobalOp(CIRGenModule &cgm, + mlir::Location loc, S

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Erich Keane via cfe-commits
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Erich Keane via cfe-commits
@@ -269,6 +269,40 @@ mlir::Operation *CIRGenModule::getGlobalValue(StringRef name) { return mlir::SymbolTable::lookupSymbolIn(theModule, name); } +cir::GlobalOp CIRGenModule::createGlobalOp(CIRGenModule &cgm, + mlir::Location loc, S

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/138222 >From b3ae2d60a178f3c5bb8950804041386a667abc6e Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Tue, 29 Apr 2025 15:47:01 -0700 Subject: [PATCH 1/2] [CIR] Refactor global variable emission and initialization

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -269,6 +269,40 @@ mlir::Operation *CIRGenModule::getGlobalValue(StringRef name) { return mlir::SymbolTable::lookupSymbolIn(theModule, name); } +cir::GlobalOp CIRGenModule::createGlobalOp(CIRGenModule &cgm, + mlir::Location loc, S

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Andy Kaylor via cfe-commits
@@ -324,8 +358,16 @@ CIRGenModule::getOrCreateCIRGlobal(StringRef mangledName, mlir::Type ty, return entry; } - errorNYI(d->getSourceRange(), "reference of undeclared global"); - return {}; + mlir::Location loc = getLoc(d->getSourceRange()); + + // mlir::SymbolTab

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Henrich Lauko via cfe-commits
https://github.com/xlauko approved this pull request. lgtm https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-02 Thread Henrich Lauko via cfe-commits
https://github.com/xlauko edited https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-01 Thread Erich Keane via cfe-commits
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-01 Thread Erich Keane via cfe-commits
https://github.com/erichkeane commented: Just 2 small comments, though I'd rather we get @bcardosolopes to take a lookhere. https://github.com/llvm/llvm-project/pull/138222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-01 Thread Erich Keane via cfe-commits
@@ -324,8 +358,16 @@ CIRGenModule::getOrCreateCIRGlobal(StringRef mangledName, mlir::Type ty, return entry; } - errorNYI(d->getSourceRange(), "reference of undeclared global"); - return {}; + mlir::Location loc = getLoc(d->getSourceRange()); + + // mlir::SymbolTab

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-01 Thread Erich Keane via cfe-commits
@@ -269,6 +269,40 @@ mlir::Operation *CIRGenModule::getGlobalValue(StringRef name) { return mlir::SymbolTable::lookupSymbolIn(theModule, name); } +cir::GlobalOp CIRGenModule::createGlobalOp(CIRGenModule &cgm, + mlir::Location loc, S

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-01 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Andy Kaylor (andykaylor) Changes When global variable support was initially upstreamed, we took some shortcuts and only implemented the minimum support for simple variables and constant initializers. This change refactors the code that c

[clang] [CIR] Refactor global variable emission and initialization (PR #138222)

2025-05-01 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/138222 When global variable support was initially upstreamed, we took some shortcuts and only implemented the minimum support for simple variables and constant initializers. This change refactors the code that cre