[clang] [CIR] Upstream basic alloca and load support (PR #128792)

David Olsen via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 26 12:16:44 PST 2025


================
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code to emit Decl nodes as CIR code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CIRGenFunction.h"
+#include "clang/AST/Expr.h"
+#include "clang/CIR/MissingFeatures.h"
+
+using namespace clang;
+using namespace clang::CIRGen;
+
+/// Emit code and set up symbol table for a variable declaration with auto,
+/// register, or no storage class specifier. These turn into simple stack
+/// objects, globals depending on target.
+void CIRGenFunction::emitAutoVarDecl(const VarDecl &d) {
+  QualType ty = d.getType();
+  assert(ty.getAddressSpace() == LangAS::Default);
----------------
dkolsen-pgi wrote:

Ideally, every not-yet-implemented or not-yet-upstreamed language construct should result in a user error, which is most easily done by calling `errorNYI`.  In the incubator, those situations usually have an `llvm_unreachable("NYI")` or an `assert(condition && "NYI")`.  We would prefer that upstream use `errorNYI` instead.  If there is code where reporting a user error is not feasible (I am not familiar enough with Clang or MLIR to know how often that will happen), then an `llvm_unreachable("NYI: <unimplemented feature>")` will have to do.

It would be great if every unimplemented language construct was checked for and resulted in an error, but I don't think that's feasible at the moment.  The number of unimplemented attributes and attribute-like properties that can be attached to declarations is huge, and adding a check for every one of them would be tedious and would overwhelm the happy-path code.  As long as the upstreamed ClangIR is unable to compile anything useful, I think this is okay.  Right now no one will compile real code and be puzzled at some subtle behavior change due to an ignored attribute.  Adding all the checks for unimplemented attributes will be important when upstreamed ClangIR is able to compile real code, and by that time many of the attributes will already be implemented and won't need a temporary NYI check.


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


More information about the cfe-commits mailing list