Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
29d4db2
[𝘀𝗽𝗿] changes to main this commit is based on
Prabhuk Nov 20, 2024
8f53618
[𝘀𝗽𝗿] initial version
Prabhuk Nov 20, 2024
a794047
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Dec 10, 2024
abfcb9c
Reorder commits.
Prabhuk Dec 10, 2024
de23806
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 12, 2025
05307cf
Update LTO compilation CodeGen flag for call-graph-section.
Prabhuk Mar 12, 2025
6a12be2
Fix EOF newlines.
Prabhuk Mar 12, 2025
a068971
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
54a3db2
Add requested tests part 1.
Prabhuk Mar 13, 2025
74044aa
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
77672ec
Update comments in tests.
Prabhuk Mar 13, 2025
1826b03
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
a8e2bd8
Updated the test as reviewers suggested.
Prabhuk Mar 13, 2025
2f7dbf2
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
3b605a6
Scoped enum. Simplify test.
Prabhuk Mar 13, 2025
7014fef
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
db11fc7
Remove unnecessary cast.
Prabhuk Mar 13, 2025
eb582bd
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
673481e
Remove unnecessary asserts. Remove autos for better readability.
Prabhuk Mar 13, 2025
6388364
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
694cfd0
Reorder IR metadata and rename temporary var names in test.
Prabhuk Mar 13, 2025
f90b397
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 14, 2025
270074f
Add RISC-V support. Clean up test files.
Prabhuk Mar 14, 2025
da8ae04
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 15, 2025
6045320
Clean up test files.
Prabhuk Mar 15, 2025
573eebe
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 19, 2025
a175709
Address review comments.
Prabhuk Mar 19, 2025
823a513
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 19, 2025
b5b2b10
Use callee_type metadata instead of OB.
Prabhuk Apr 19, 2025
2cac836
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 19, 2025
5ede050
Address review comments.
Prabhuk Apr 19, 2025
0c78d0a
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 23, 2025
d0a96ac
Rebase on top of llvm stack.
Prabhuk Apr 23, 2025
7a1c8fb
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 23, 2025
89c896b
Rebase on parent llvm change.
Prabhuk Apr 23, 2025
a56ccb8
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 23, 2025
c53d51d
Address review comments.
Prabhuk Apr 23, 2025
ab46191
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 24, 2025
839da25
Address review comments.
Prabhuk Apr 24, 2025
5b36796
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 24, 2025
43d6eed
Rebase on parent.
Prabhuk Apr 24, 2025
05057b8
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 24, 2025
5188f32
Rebase on parent.
Prabhuk Apr 24, 2025
2131b83
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 28, 2025
c5a12e9
Rebase on parent.
Prabhuk Apr 28, 2025
759a709
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 29, 2025
5cdb84e
Rebase on llvm changes.
Prabhuk Apr 29, 2025
32c7adb
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 1, 2025
75dec8e
Rebase on parent.
Prabhuk May 1, 2025
8a289b1
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 5, 2025
e0020f5
Rebase on parent.
Prabhuk May 5, 2025
9c21da8
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 10, 2025
f165443
Rebase on parent change.
Prabhuk May 10, 2025
f83a155
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 13, 2025
2745a8a
Rebase on parent llvm changes.
Prabhuk May 13, 2025
03ad07f
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 13, 2025
12df871
Rebase on parent.
Prabhuk May 13, 2025
edf799d
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 14, 2025
2a3c23d
Rebase on parent
Prabhuk May 14, 2025
d04642b
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 14, 2025
d4d4533
Rebase on main.
Prabhuk May 14, 2025
8bbbe12
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 27, 2025
37d3ef9
Rebase on parent.
Prabhuk May 27, 2025
ca6d2cc
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 27, 2025
c02cbb9
Rebase change.
Prabhuk May 27, 2025
8f07a4c
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jun 11, 2025
b16770b
Rebase.
Prabhuk Jun 11, 2025
0e29abc
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jun 11, 2025
1e773e1
Rebase on parent
Prabhuk Jun 11, 2025
38fc4f5
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 10, 2025
7b9cbb3
Rebase on top of main.
Prabhuk Jul 10, 2025
b7d5e7f
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
9591c3a
Rebase on parent.
Prabhuk Jul 18, 2025
c262b69
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
07f7768
Rebase on parent
Prabhuk Jul 18, 2025
125ddcd
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
15a1b29
Rebase on top of parent change.
Prabhuk Jul 18, 2025
9eff07d
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
1c0f1ab
Rebase on parent.
Prabhuk Jul 18, 2025
1ba8c04
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
0c1ec48
Rebase on parent.
Prabhuk Jul 18, 2025
c9f6c5c
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
9592631
Address review comments.
Prabhuk Jul 18, 2025
c09082e
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 21, 2025
80c3580
Rebase on parent.
Prabhuk Jul 21, 2025
c67f714
Fix review comment on test file.
Prabhuk Jul 21, 2025
7f95a40
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 22, 2025
410bb0d
Rebase.
Prabhuk Jul 22, 2025
7321a3e
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 23, 2025
66c858e
Rebase on parent llvm change.
Prabhuk Jul 23, 2025
2d81ecc
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 23, 2025
c2294fa
Rebase on main.
Prabhuk Jul 23, 2025
571a431
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 23, 2025
6884d2a
Rebase.
Prabhuk Jul 23, 2025
036be4e
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 28, 2025
1fb27f8
Rebase on parent.
Prabhuk Jul 28, 2025
4ec81ea
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 28, 2025
9d29e55
Rebase on llvm changes.
Prabhuk Jul 28, 2025
23c8579
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 30, 2025
00f7d91
Rebase on main.
Prabhuk Jul 30, 2025
2924f11
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 31, 2025
0aa3d97
Rebase on main.
Prabhuk Jul 31, 2025
50a5786
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 31, 2025
a6b4a13
Rebase on parent.
Prabhuk Jul 31, 2025
f4d6c96
Rebase on main.
Prabhuk Jul 31, 2025
d349feb
Make Driver flag experimental.
Prabhuk Jul 31, 2025
d50a454
Merge branch 'main' into users/Prabhuk/sprclangcallgraphsection-add-c…
Prabhuk Oct 10, 2025
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
251 changes: 251 additions & 0 deletions clang/docs/CallGraphSection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
==================
Call Graph Section
==================

Introduction
============

With ``-fcall-graph-section``, the compiler will create a call graph section
in the object file. It will include type identifiers for indirect calls and
targets. This information can be used to map indirect calls to their receivers
with matching types. A complete and high-precision call graph can be
reconstructed by complementing this information with disassembly
(see ``llvm-objdump --call-graph-info``).

Semantics
=========

A coarse-grained, type-agnostic call graph may allow indirect calls to target
any function in the program. This approach ensures completeness since no
indirect call edge is missing. However, it is generally poor in precision
due to having unneeded edges.

A call graph section provides type identifiers for indirect calls and targets.
This information can be used to restrict the receivers of an indirect target to
indirect calls with matching type. Consequently, the precision for indirect
call edges are improved while maintaining the completeness.

The ``llvm-objdump`` utility provides a ``--call-graph-info`` option to extract
full call graph information by parsing the content of the call graph section
and disassembling the program for complementary information, e.g., direct
calls.

Section layout
==============

A call graph section consists of zero or more call graph entries.
Each entry contains information on a function and its indirect calls.

An entry of a call graph section has the following layout in the binary:

+---------------------+-----------------------------------------------------------------------+
| Element | Content |
+=====================+=======================================================================+
| FormatVersionNumber | Format version number. |
+---------------------+-----------------------------------------------------------------------+
| FunctionEntryPc | Function entry address. |
+---------------------+-----------------------------------+-----------------------------------+
| | A flag whether the function is an | - 0: not an indirect target |
| FunctionKind | indirect target, and if so, | - 1: indirect target, unknown id |
| | whether its type id is known. | - 2: indirect target, known id |
+---------------------+-----------------------------------+-----------------------------------+
| FunctionTypeId | Type id for the indirect target. Present only when FunctionKind is 2. |
+---------------------+-----------------------------------------------------------------------+
| CallSiteCount | Number of type id to indirect call site mappings that follow. |
+---------------------+-----------------------------------------------------------------------+
| CallSiteList | List of type id and indirect call site pc pairs. |
+---------------------+-----------------------------------------------------------------------+

Each element in an entry (including each element of the contained lists and
pairs) occupies 64-bit space.

The format version number is repeated per entry to support concatenation of
call graph sections with different format versions by the linker.

As of now, the only supported format version is described above and has version
number 0.

Type identifiers
================

The type for an indirect call or target is the function signature.
The mapping from a type to an identifier is an ABI detail.
In the current experimental implementation, an identifier of type T is
computed as follows:

- Obtain the generalized mangled name for “typeinfo name for T”.
- Compute MD5 hash of the name as a string.
- Reinterpret the first 8 bytes of the hash as a little-endian 64-bit integer.

To avoid mismatched pointer types, generalizations are applied.
Pointers in return and argument types are treated as equivalent as long as the
qualifiers for the type they point to match.
For example, ``char*``, ``char**``, and ``int*`` are considered equivalent
types. However, ``char*`` and ``const char*`` are considered separate types.

Missing type identifiers
========================

For functions, two cases need to be considered. First, if the compiler cannot
deduce a type id for an indirect target, it will be listed as an indirect target
without a type id. Second, if an object without a call graph section gets
linked, the final call graph section will lack information on functions from
the object. For completeness, these functions need to be taken as receiver to
any indirect call regardless of their type id.
``llvm-objdump --call-graph-info`` lists these functions as indirect targets
with `UNKNOWN` type id.

For indirect calls, current implementation guarantees a type id for each
compiled call. However, if an object without a call graph section gets linked,
no type id will be present for its indirect calls. For completeness, these calls
need to be taken to target any indirect target regardless of their type id. For
indirect calls, ``llvm-objdump --call-graph-info`` prints 1) a complete list of
indirect calls, 2) type id to indirect call mappings. The difference of these
lists allow to deduce the indirect calls with missing type ids.

TODO: measure and report the ratio of missed type ids

Performance
===========

A call graph section does not affect the executable code and does not occupy
memory during process execution. Therefore, there is no performance overhead.

The scheme has not yet been optimized for binary size.

TODO: measure and report the increase in the binary size

Example
=======

For example, consider the following C++ code:

.. code-block:: cpp
namespace {
// Not an indirect target
void foo() {}
}
// Indirect target 1
void bar() {}
// Indirect target 2
int baz(char a, float *b) {
return 0;
}
// Indirect target 3
int main() {
char a;
float b;
void (*fp_bar)() = bar;
int (*fp_baz1)(char, float*) = baz;
int (*fp_baz2)(char, float*) = baz;
// Indirect call site 1
fp_bar();
// Indirect call site 2
fp_baz1(a, &b);
// Indirect call site 3: shares the type id with indirect call site 2
fp_baz2(a, &b);
// Direct call sites
foo();
bar();
baz(a, &b);
return 0;
}
Following will compile it with a call graph section created in the binary:

.. code-block:: bash
$ clang -fcall-graph-section example.cpp
During the construction of the call graph section, the type identifiers are
computed as follows:

+---------------+-----------------------+----------------------------+----------------------------+
| Function name | Generalized signature | Mangled name (itanium ABI) | Numeric type id (md5 hash) |
+===============+=======================+============================+============================+
| bar | void () | _ZTSFvvE.generalized | f85c699bb8ef20a2 |
+---------------+-----------------------+----------------------------+----------------------------+
| baz | int (char, void*) | _ZTSFicPvE.generalized | e3804d2a7f2b03fe |
+---------------+-----------------------+----------------------------+----------------------------+
| main | int () | _ZTSFivE.generalized | a9494def81a01dc |
+---------------+-----------------------+----------------------------+----------------------------+

The call graph section will have the following content:

+---------------+-----------------+--------------+----------------+---------------+--------------------------------------+
| FormatVersion | FunctionEntryPc | FunctionKind | FunctionTypeId | CallSiteCount | CallSiteList |
+===============+=================+==============+================+===============+======================================+
| 0 | EntryPc(foo) | 0 | (empty) | 0 | (empty) |
+---------------+-----------------+--------------+----------------+---------------+--------------------------------------+
| 0 | EntryPc(bar) | 2 | TypeId(bar) | 0 | (empty) |
+---------------+-----------------+--------------+----------------+---------------+--------------------------------------+
| 0 | EntryPc(baz) | 2 | TypeId(baz) | 0 | (empty) |
+---------------+-----------------+--------------+----------------+---------------+--------------------------------------+
| 0 | EntryPc(main) | 2 | TypeId(main) | 3 | * TypeId(bar), CallSitePc(fp_bar()) |
| | | | | | * TypeId(baz), CallSitePc(fp_baz1()) |
| | | | | | * TypeId(baz), CallSitePc(fp_baz2()) |
+---------------+-----------------+--------------+----------------+---------------+--------------------------------------+


The ``llvm-objdump`` utility can parse the call graph section and disassemble
the program to provide complete call graph information. This includes any
additional call sites from the binary:

.. code-block:: bash
$ llvm-objdump --call-graph-info a.out
# Comments are not a part of the llvm-objdump's output but inserted for clarifications.
a.out: file format elf64-x86-64
# These warnings are due to the functions and the indirect calls coming from linked objects.
llvm-objdump: warning: 'a.out': callgraph section does not have type ids for 3 indirect calls
llvm-objdump: warning: 'a.out': callgraph section does not have information for 10 functions
# Unknown targets are the 10 functions the warnings mention.
INDIRECT TARGET TYPES (TYPEID [FUNC_ADDR,])
UNKNOWN 401000 401100 401234 401050 401090 4010d0 4011d0 401020 401060 401230
a9494def81a01dc 401150 # main()
f85c699bb8ef20a2 401120 # bar()
e3804d2a7f2b03fe 401130 # baz()
# Notice that the call sites share the same type id as target functions
INDIRECT CALL TYPES (TYPEID [CALL_SITE_ADDR,])
f85c699bb8ef20a2 401181 # Indirect call site 1 (fp_bar())
e3804d2a7f2b03fe 401191 4011a1 # Indirect call site 2 and 3 (fp_baz1() and fp_baz2())
INDIRECT CALL SITES (CALLER_ADDR [CALL_SITE_ADDR,])
401000 401012 # _init
401150 401181 401191 4011a1 # main calls fp_bar(), fp_baz1(), fp_baz2()
4011d0 401215 # __libc_csu_init
401020 40104a # _start
DIRECT CALL SITES (CALLER_ADDR [(CALL_SITE_ADDR, TARGET_ADDR),])
4010d0 4010e2 401060 # __do_global_dtors_aux
401150 4011a6 401110 4011ab 401120 4011ba 401130 # main calls foo(), bar(), baz()
4011d0 4011fd 401000 # __libc_csu_init
FUNCTIONS (FUNC_ENTRY_ADDR, SYM_NAME)
401000 _init
401100 frame_dummy
401234 _fini
401050 _dl_relocate_static_pie
401090 register_tm_clones
4010d0 __do_global_dtors_aux
401110 _ZN12_GLOBAL__N_13fooEv # (anonymous namespace)::foo()
401150 main # main
4011d0 __libc_csu_init
401020 _start
401060 deregister_tm_clones
401120 _Z3barv # bar()
401130 _Z3bazcPf # baz(char, float*)
401230 __libc_csu_fini
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ CODEGENOPT(EnableNoundefAttrs, 1, 0) ///< Enable emitting `noundef` attributes o
CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled.
CODEGENOPT(CallGraphSection, 1, 0) ///< Emit a call graph section into the
///< object file.
CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
///< '-g' + 'O>0' level.
CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4291,6 +4291,10 @@ defm data_sections : BoolFOption<"data-sections",
PosFlag<SetTrue, [], [ClangOption, CC1Option],
"Place each data in its own section">,
NegFlag<SetFalse>>;
defm call_graph_section : BoolFOption<"call-graph-section",
CodeGenOpts<"CallGraphSection">, DefaultFalse,
PosFlag<SetTrue, [], [CC1Option], "Emit a call graph section">,
NegFlag<SetFalse>>;
defm stack_size_section : BoolFOption<"stack-size-section",
CodeGenOpts<"StackSizeSection">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option],
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.StackUsageOutput = CodeGenOpts.StackUsageOutput;
Options.EmitAddrsig = CodeGenOpts.Addrsig;
Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
Options.EmitCallGraphSection = CodeGenOpts.CallGraphSection;
Copy link
Contributor

Choose a reason for hiding this comment

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

TargetOptions :(

Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
Expand Down
38 changes: 38 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Type.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CodeGen/CGFunctionInfo.h"
Expand Down Expand Up @@ -5077,6 +5078,11 @@ static unsigned getMaxVectorWidth(const llvm::Type *Ty) {
return MaxVectorWidth;
}

static bool isCXXDeclType(const FunctionDecl *FD) {
return isa<CXXConstructorDecl>(FD) || isa<CXXMethodDecl>(FD) ||
isa<CXXDestructorDecl>(FD);
}

RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
const CGCallee &Callee,
ReturnValueSlot ReturnValue,
Expand Down Expand Up @@ -5765,6 +5771,38 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
AllocAlignAttrEmitter AllocAlignAttrEmitter(*this, TargetDecl, CallArgs);
Attrs = AllocAlignAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);

if (CGM.getCodeGenOpts().CallGraphSection) {
// Create operand bundle only for indirect calls, not for all
if (callOrInvoke && *callOrInvoke && (*callOrInvoke)->isIndirectCall()) {

assert((TargetDecl && TargetDecl->getFunctionType() ||
Callee.getAbstractInfo().getCalleeFunctionProtoType()) &&
"cannot find callsite type");

QualType CST;
if (TargetDecl && TargetDecl->getFunctionType())
CST = QualType(TargetDecl->getFunctionType(), 0);
else if (const auto *FPT =
Callee.getAbstractInfo().getCalleeFunctionProtoType())
CST = QualType(FPT, 0);

if (!CST.isNull()) {
auto *TypeIdMD = CGM.CreateMetadataIdentifierGeneralized(CST);
auto *TypeIdMDVal =
llvm::MetadataAsValue::get(getLLVMContext(), TypeIdMD);
BundleList.emplace_back("type", TypeIdMDVal);
}

// Set type identifier metadata of indirect calls for call graph section.
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
// Type id metadata is set only for C/C++ contexts.
if (isCXXDeclType(FD)) {
CGM.CreateFunctionTypeMetadataForIcall(FD->getType(), *callOrInvoke);
}
}
}
}

// Emit the actual call/invoke instruction.
llvm::CallBase *CI;
if (!InvokeDest) {
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6173,6 +6173,12 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
if (CallOrInvoke)
*CallOrInvoke = LocalCallOrInvoke;

// Set type identifier metadata of indirect calls for call graph section.
if (CGM.getCodeGenOpts().CallGraphSection && LocalCallOrInvoke &&
LocalCallOrInvoke->isIndirectCall())
CGM.CreateFunctionTypeMetadataForIcall(QualType(FnType, 0),
LocalCallOrInvoke);

return Call;
}

Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGObjCMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,9 +2214,8 @@ CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,

llvm::CallBase *CallSite;
CGCallee Callee = CGCallee::forDirect(BitcastFn);
RValue rvalue = CGF.EmitCall(MSI.CallInfo, Callee, Return, ActualArgs,
&CallSite);

RValue rvalue =
CGF.EmitCall(MSI.CallInfo, Callee, Return, ActualArgs, &CallSite);
// Mark the call as noreturn if the method is marked noreturn and the
// receiver cannot be null.
if (Method && Method->hasAttr<NoReturnAttr>() && !ReceiverCanBeNull) {
Expand Down
Loading
Loading