blob: 89234fa483497e2f43db6a2b3da4422ee33094b1 [file] [edit]
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -std=c++20 -emit-llvm -o %t/on.ll %t/main.cpp
// RUN: FileCheck %s --check-prefix=INL < %t/on.ll
// RUN: FileCheck %s --check-prefix=TMPL < %t/on.ll
// RUN: FileCheck %s --check-prefix=LAMBDA < %t/on.ll
// RUN: FileCheck %s --check-prefix=MEMBER < %t/on.ll
// RUN: FileCheck %s --check-prefix=PLAIN < %t/on.ll
// RUN: FileCheck %s --check-prefix=HDR < %t/on.ll
// RUN: FileCheck %s --check-prefix=HDRTMPL < %t/on.ll
// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -std=c++20 -emit-llvm -fno-module-local-hints -o - %t/main.cpp | FileCheck %s --check-prefix=OFF
// Preprocessed source: the line markers (as emitted by -E) still attribute
// hdr.h's code to hdr.h, so the result must be the same.
// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -std=c++20 -E -o %t/main.ii %t/main.cpp
// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -std=c++20 -emit-llvm -x c++-cpp-output -o %t/pp.ll %t/main.ii
// RUN: FileCheck %s --check-prefix=INL < %t/pp.ll
// RUN: FileCheck %s --check-prefix=TMPL < %t/pp.ll
// RUN: FileCheck %s --check-prefix=LAMBDA < %t/pp.ll
// RUN: FileCheck %s --check-prefix=MEMBER < %t/pp.ll
// RUN: FileCheck %s --check-prefix=PLAIN < %t/pp.ll
// RUN: FileCheck %s --check-prefix=HDR < %t/pp.ll
// RUN: FileCheck %s --check-prefix=HDRTMPL < %t/pp.ll
//--- hdr.h
inline int hdr_inline(int x) { return x * 3; }
template <class F> int hdr_call(F f) { return f(); }
//--- main.cpp
#include "hdr.h"
struct S { int m(int x) { return x - 1; } };
int main_plain(int x) { return x + 1; }
inline int main_inline(int x) { return x * 7; }
template <class T> int main_tmpl(T x) { return hdr_call([&] { return x * 2; }); }
int use(int x) {
return main_plain(x) + main_inline(x) + main_tmpl(x) + hdr_inline(x) +
S().m(x);
}
// Inline functions, template instantiations and lambdas defined in main.cpp.
// These may share an attribute group, so each is checked by a separate run.
// INL: define{{.*}} i32 @_Z11main_inlinei({{.*}}) #[[INL:[0-9]+]]
// INL: attributes #[[INL]] = { {{.*}}likely_module_local{{.*}} }
// TMPL: define{{.*}} i32 @_Z9main_tmplIiEiT_({{.*}}) #[[TMPL:[0-9]+]]
// TMPL: attributes #[[TMPL]] = { {{.*}}likely_module_local{{.*}} }
// LAMBDA: define{{.*}} i32 @_ZZ9main_tmplIiEiT_ENKUlvE_clEv({{.*}}) #[[LAMBDA:[0-9]+]]
// LAMBDA: attributes #[[LAMBDA]] = { {{.*}}likely_module_local{{.*}} }
// MEMBER: define{{.*}} i32 @_ZN1S1mEi({{.*}}) #[[MEMBER:[0-9]+]]
// MEMBER: attributes #[[MEMBER]] = { {{.*}}likely_module_local{{.*}} }
// Non-inline functions in main.cpp.
// PLAIN-DAG: define{{.*}} i32 @_Z10main_plaini({{.*}}) #[[PLAIN:[0-9]+]]
// PLAIN-DAG: define{{.*}} i32 @_Z3usei({{.*}}) #[[PLAIN]]
// PLAIN: attributes #[[PLAIN]] = {
// PLAIN-NOT: likely_module_local
// PLAIN-SAME: }
// Inline function defined in hdr.h.
// HDR: define{{.*}} i32 @_Z10hdr_inlinei({{.*}}) #[[HDR:[0-9]+]]
// HDR: attributes #[[HDR]] = {
// HDR-NOT: likely_module_local
// HDR-SAME: }
// Template defined in hdr.h, instantiated (with a main.cpp lambda) in main.cpp.
// HDRTMPL: define{{.*}} i32 @_Z8hdr_call{{.*}}) #[[HDRTMPL:[0-9]+]]
// HDRTMPL: attributes #[[HDRTMPL]] = {
// HDRTMPL-NOT: likely_module_local
// HDRTMPL-SAME: }
// OFF-NOT: likely_module_local