Skip to content

Commit c1d5cc9

Browse files
[LangRef] Try to formalize the definition of "odr" in LLVM IR. (llvm#92619)
The current definition is a bit fuzzy... replace it with something that's somewhat rigorous. For functions, the definition is pretty narrow; as a consequence of language-level non-determinism, it's impossible to tell whether two functions are equivalent, so just embrace the non-determinism. For constants, we're pretty strict; otherwise you end up concluding constants can actually change value, which is bad for alias analysis. I think C++ standard don't allow any non-deterministic operations in constants, so we should be okay there? Poison is per-byte to allow some ambiguity in the way padding is defined.
1 parent fdd245a commit c1d5cc9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

llvm/docs/LangRef.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,17 @@ linkage:
290290
symbol is weak until linked, if not linked, the symbol becomes null
291291
instead of being an undefined reference.
292292
``linkonce_odr``, ``weak_odr``
293-
Some languages allow differing globals to be merged, such as two
294-
functions with different semantics. Other languages, such as
295-
``C++``, ensure that only equivalent globals are ever merged (the
296-
"one definition rule" --- "ODR"). Such languages can use the
297-
``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the
298-
global will only be merged with equivalent globals. These linkage
299-
types are otherwise the same as their non-``odr`` versions.
293+
The ``odr`` suffix indicates that all globals defined with the given name
294+
are equivalent, along the lines of the C++ "one definition rule" ("ODR").
295+
Informally, this means we can inline functions and fold loads of constants.
296+
297+
Formally, use the following definition: when an ``odr`` function is
298+
called, one of the definitions is non-deterministically chosen to run. For
299+
``odr`` variables, if any byte in the value is not equal in all
300+
initializers, that byte is a :ref:`poison value <poisonvalues>`. For
301+
aliases and ifuncs, apply the rule for the underlying function or variable.
302+
303+
These linkage types are otherwise the same as their non-``odr`` versions.
300304
``external``
301305
If none of the above identifiers are used, the global is externally
302306
visible, meaning that it participates in linkage and can be used to

0 commit comments

Comments
 (0)