From b9ee28ad551effe86e64964cc210aeac73cdde08 Mon Sep 17 00:00:00 2001 From: Letu Ren Date: Wed, 19 Mar 2025 06:49:04 +0800 Subject: [PATCH] [CIR] Backport clang commit to unxfail some builtin call --- clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 8 +++++--- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 3 ++- clang/test/CIR/CodeGen/builtins-memory.c | 1 - clang/test/CIR/CodeGen/builtins.cpp | 1 - clang/test/CIR/CodeGen/libcall.cpp | 1 - clang/test/CIR/Lowering/builtin-binary-fp2fp.c | 1 - 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 78d96c39396b..56573e6455ca 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -2771,8 +2771,10 @@ cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *FD, unsigned BuiltinID) { assert(astContext.BuiltinInfo.isLibFunction(BuiltinID)); - // Get the name, skip over the __builtin_ prefix (if necessary). - StringRef Name; + // Get the name, skip over the __builtin_ prefix (if necessary). We may have + // to build this up so provide a small stack buffer to handle the vast + // majority of names. + llvm::SmallString<64> Name; GlobalDecl D(FD); // TODO: This list should be expanded or refactored after all GCC-compatible @@ -2831,7 +2833,7 @@ cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *FD, AIXLongDouble64Builtins.end()) Name = AIXLongDouble64Builtins[BuiltinID]; else - Name = StringRef(astContext.BuiltinInfo.getName(BuiltinID).data(), 10); + Name = astContext.BuiltinInfo.getName(BuiltinID).substr(10); } auto Ty = convertType(FD->getType()); diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 6c2c907f0573..8ae34d99eeed 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -3650,7 +3650,8 @@ struct FunctionIsDirectlyRecursive unsigned builtinId = func->getBuiltinID(); if (!builtinId || !builtinCtx.isLibFunction(builtinId)) return false; - StringRef builtinName = builtinCtx.getName(builtinId); + std::string builtinNameStr = builtinCtx.getName(builtinId); + StringRef builtinName = builtinNameStr; return builtinName.starts_with("__builtin_") && name == builtinName.slice(strlen("__builtin_"), StringRef::npos); } diff --git a/clang/test/CIR/CodeGen/builtins-memory.c b/clang/test/CIR/CodeGen/builtins-memory.c index a6401b92eb12..9c7a74301aaa 100644 --- a/clang/test/CIR/CodeGen/builtins-memory.c +++ b/clang/test/CIR/CodeGen/builtins-memory.c @@ -3,7 +3,6 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - \ // RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s -// XFAIL: * typedef __SIZE_TYPE__ size_t; void test_memcpy_chk(void *dest, const void *src, size_t n) { diff --git a/clang/test/CIR/CodeGen/builtins.cpp b/clang/test/CIR/CodeGen/builtins.cpp index a0e27c49c3d7..504ec13da6ee 100644 --- a/clang/test/CIR/CodeGen/builtins.cpp +++ b/clang/test/CIR/CodeGen/builtins.cpp @@ -4,7 +4,6 @@ // RUN: -emit-llvm -fno-clangir-call-conv-lowering -o - %s \ // RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s -// XFAIL: * // This test file is a collection of test cases for all target-independent // builtins that are related to memory operations. diff --git a/clang/test/CIR/CodeGen/libcall.cpp b/clang/test/CIR/CodeGen/libcall.cpp index 990240e75746..192b0ff13294 100644 --- a/clang/test/CIR/CodeGen/libcall.cpp +++ b/clang/test/CIR/CodeGen/libcall.cpp @@ -1,6 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -mconstructor-aliases -emit-cir %s -o %t.cir // RUN: FileCheck --input-file=%t.cir %s -// XFAIL: * typedef __builtin_va_list va_list; diff --git a/clang/test/CIR/Lowering/builtin-binary-fp2fp.c b/clang/test/CIR/Lowering/builtin-binary-fp2fp.c index d44444769889..2877aa5cef30 100644 --- a/clang/test/CIR/Lowering/builtin-binary-fp2fp.c +++ b/clang/test/CIR/Lowering/builtin-binary-fp2fp.c @@ -2,7 +2,6 @@ // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -ffast-math -fclangir -emit-llvm %s -o %t.ll // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM-FASTMATH -// XFAIL: * // copysign