Debian Codegraph @

include/ruby/internal/attr/noalias.h

raw
1 #ifndef RBIMPL_ATTR_NOALIAS_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_ATTR_NOALIAS_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Defines #RBIMPL_ATTR_NOALIAS.
22 *
23 * ### Q&A ###
24 *
25 * - Q: There are seemingly similar attributes named #RBIMPL_ATTR_CONST,
26 * #RBIMPL_ATTR_PURE, and #RBIMPL_ATTR_NOALIAS. What are the difference?
27 *
28 * - A: Allowed operations are different.
29 *
30 * - #RBIMPL_ATTR_CONST ... Functions attributed by this are not allowed to
31 * read/write _any_ pointers at all (there are exceptional situations
32 * when reading a pointer is possible but forget that; they are too
33 * exceptional to be useful). Just remember that everything pointer-
34 * related are NG.
35 *
36 * - #RBIMPL_ATTR_PURE ... Functions attributed by this can read any
37 * nonvolatile pointers, but no writes are allowed at all. The ability
38 * to read _any_ nonvolatile pointers makes it possible to mark ::VALUE-
39 * taking functions as being pure, as long as they are read-only.
40 *
41 * - #RBIMPL_ATTR_NOALIAS ... Can both read/write, but only through
42 * pointers passed to the function as parameters. This is a typical
43 * situation when you create a C++ non-static member function which only
44 * concerns `this`. No global variables are allowed to read/write. So
45 * this is not a super-set of being pure. If you want to read something,
46 * that has to be passed to the function as a pointer. ::VALUE -taking
47 * functions thus cannot be attributed as such.
48 */
49 #include "ruby/internal/compiler_since.h"
50 #include "ruby/internal/has/declspec_attribute.h"
51
52 /** Wraps (or simulates) `__declspec((noalias))` */
53 #if RBIMPL_COMPILER_BEFORE(Clang, 12, 0, 0)
54 # /*
55 # * `::llvm::Attribute::ArgMemOnly` was buggy before. Maybe because nobody
56 # * actually seriously used it. It seems they somehow mitigated the situation
57 # * in LLVM 12. Still not found the exact changeset which fiexed the
58 # * attribute, though.
59 # *
60 # * :FIXME: others (armclang, xlclang, ...) can also be affected?
61 # */
62 # define RBIMPL_ATTR_NOALIAS() /* void */
63 #elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias)
64 # define RBIMPL_ATTR_NOALIAS() __declspec(noalias)
65 #else
66 # define RBIMPL_ATTR_NOALIAS() /* void */
67 #endif
68
69 #endif /* RBIMPL_ATTR_NOALIAS_H */