[llvm] 2dad7ee - [LangRef] Document integer hexadecimal constants
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 18 10:05:32 PDT 2023
Author: Luke Lau
Date: 2023-08-18T18:05:25+01:00
New Revision: 2dad7eeaaae8e5eca64fb3ce162ab2a8a9d2134a
URL: https://github.com/llvm/llvm-project/commit/2dad7eeaaae8e5eca64fb3ce162ab2a8a9d2134a
DIFF: https://github.com/llvm/llvm-project/commit/2dad7eeaaae8e5eca64fb3ce162ab2a8a9d2134a.diff
LOG: [LangRef] Document integer hexadecimal constants
It's possible to write an integer constant in hexadecimal, but you need to
prefix it with u or s. I couldn't find this mentioned anywhere in the LangRef,
so this adds a small note about it.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D158288
Added:
Modified:
llvm/docs/LangRef.rst
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f7f5cc193a149c..86675c162c11f1 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -4093,9 +4093,17 @@ Simple Constants
The two strings '``true``' and '``false``' are both valid constants
of the ``i1`` type.
**Integer constants**
- Standard integers (such as '4') are constants of the
- :ref:`integer <t_integer>` type. Negative numbers may be used with
- integer types.
+ Standard integers (such as '4') are constants of the :ref:`integer
+ <t_integer>` type. They can be either decimal or
+ hexadecimal. Decimal integers can be prefixed with - to represent
+ negative integers, e.g. '``-1234``'. Hexadecimal integers must be
+ prefixed with either u or s to indicate whether they are unsigned
+ or signed respectively. e.g '``u0x8000``' gives 32768, whilst
+ '``s0x8000``' gives -32768.
+
+ Note that hexadecimal integers are sign extended from the number
+ of active bits, i.e. the bit width minus the number of leading
+ zeros. So '``s0x0001``' of type '``i16``' will be -1, not 1.
**Floating-point constants**
Floating-point constants use standard decimal notation (e.g.
123.421), exponential notation (e.g. 1.23421e+2), or a more precise
More information about the llvm-commits
mailing list