Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ struct MissingFeatures {
static bool lambdaFieldToName() { return false; }
static bool targetSpecificCXXABI() { return false; }
static bool moduleNameHash() { return false; }
static bool setDSOLocal() { return false; }

// Missing types
static bool dataMemberType() { return false; }
Expand Down
52 changes: 52 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,58 @@ cir::FuncOp CIRGenModule::getOrCreateCIRFunction(
StringRef mangledName, mlir::Type funcType, GlobalDecl gd, bool forVTable,
bool dontDefer, bool isThunk, ForDefinition_t isForDefinition,
mlir::ArrayAttr extraAttrs) {
const Decl *d = gd.getDecl();

if (isThunk)
errorNYI(d->getSourceRange(), "getOrCreateCIRFunction: thunk");

// In what follows, we continue past 'errorNYI' as if nothing happened because
// the rest of the implementation is better than doing nothing.

// Any attempts to use a MultiVersion function should result in retrieving the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment out of place? Looks like it should be with the actual multiversion stuff on 793.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. When this comment was originally written (by you, incidentally), line 793 immediately followed line 786, so the comment made sense here. When the OpenMP handling was added, the comment wasn't moved but it should have been. I'll fix that here. The classic codegen will still have this comment location issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in classic-codegen: 785ab45

// iFunc instead. Name mangling will handle the rest of the changes.
if (const auto *fd = cast_or_null<FunctionDecl>(d)) {
// For the device mark the function as one that should be emitted.
if (getLangOpts().OpenMPIsTargetDevice && fd->isDefined() && !dontDefer &&
!isForDefinition)
errorNYI(fd->getSourceRange(),
"getOrCreateCIRFunction: OpenMP target function");

if (fd->isMultiVersion())
errorNYI(fd->getSourceRange(), "multi-version functions NYI");
}

// Lookup the entry, lazily creating it if necessary.
mlir::Operation *entry = getGlobalValue(mangledName);
if (entry) {
if (!isa<cir::FuncOp>(entry))
errorNYI(d->getSourceRange(), "getOrCreateCIRFunction: non-FuncOp");

assert(!cir::MissingFeatures::weakRefReference());

// Handle dropped DLL attributes.
if (d && !d->hasAttr<DLLImportAttr>() && !d->hasAttr<DLLExportAttr>()) {
assert(!cir::MissingFeatures::setDLLStorageClass());
assert(!cir::MissingFeatures::setDSOLocal());
}

// If there are two attempts to define the same mangled name, issue an
// error.
auto fn = cast<cir::FuncOp>(entry);
assert((!isForDefinition || !fn || !fn.isDeclaration()) &&
"Duplicate function definition");
if (fn && fn.getFunctionType() == funcType) {
return fn;
}

if (!isForDefinition) {
return fn;
}

// TODO(cir): classic codegen checks here if this is a llvm::GlobalAlias.
// How will we support this?
}

auto *funcDecl = llvm::cast_or_null<FunctionDecl>(gd.getDecl());
bool invalidLoc = !funcDecl ||
funcDecl->getSourceRange().getBegin().isInvalid() ||
Expand Down
11 changes: 6 additions & 5 deletions clang/test/CIR/CodeGen/call.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | FileCheck %s

void f1();
void f1() {}
void f2() {
f1();
}

// CHECK-LABEL: cir.func @_Z2f1v
// CHECK-LABEL: cir.func @_Z2f1v
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the leading spaces weird here?

// CHECK-LABEL: cir.func @_Z2f2v
// CHECK: cir.call @_Z2f1v() : () -> ()

int f3();
int f3() { return 2; }
int f4() {
int x = f3();
return x;
}

// CHECK-LABEL: cir.func @_Z2f3v() -> !s32i
// CHECK-LABEL: cir.func @_Z2f4v() -> !s32i
// CHECK: %[[#x:]] = cir.call @_Z2f3v() : () -> !s32i
// CHECK-NEXT: cir.store %[[#x]], %{{.+}} : !s32i, !cir.ptr<!s32i>
// CHECK: cir.call @_Z2f3v() : () -> !s32i
5 changes: 1 addition & 4 deletions clang/test/CIR/CodeGen/namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
namespace {
int g1 = 1;

// Note: This causes a warning about the function being undefined, but we
// currently have a problem with duplicate definitions when we call functions.
// This should be updated when that problem is fixed.
void f1(void);
void f1(void) {}
}


Expand Down
Loading