1 //===---------------------------------------------------------------------===//
3 //===---------------------------------------------------------------------===//
5 C90/C99/C++ Comparisons:
6 http://david.tribble.com/text/cdiffs.htm
8 //===---------------------------------------------------------------------===//
11 * "#define_target X Y"
12 This preprocessor directive works exactly the same was as #define, but it
13 notes that 'X' is a target-specific preprocessor directive. When used, a
14 diagnostic is emitted indicating that the translation unit is non-portable.
16 If a target-define is #undef'd before use, no diagnostic is emitted. If 'X'
17 were previously a normal #define macro, the macro is tainted. If 'X' is
18 subsequently #defined as a non-target-specific define, the taint bit is
21 * "#define_other_target X"
22 The preprocessor directive takes a single identifier argument. It notes
23 that this identifier is a target-specific #define for some target other than
24 the current one. Use of this identifier will result in a diagnostic.
26 If 'X' is later #undef'd or #define'd, the taint bit is cleared. If 'X' is
27 already defined, X is marked as a target-specific define.
29 //===---------------------------------------------------------------------===//
31 When we go to reimplement <tgmath.h>, we should do it more intelligently than
32 the GCC-supplied header. EDG has an interesting __generic builtin that provides
34 http://www.edg.com/docs/edg_cpp.pdf
36 For example, they have:
37 #define sin(x) __generic(x,,, sin, sinf, sinl, csin, csinf,csinl)(x)
39 It's unclear to me why you couldn't just have a builtin like:
40 __builtin_overload(1, arg1, impl1, impl2, impl3)
41 __builtin_overload(2, arg1, arg2, impl1, impl2, impl3)
42 __builtin_overload(3, arg1, arg2, arg3, impl1, impl2, impl3)
44 Where the compiler would just pick the right "impl" based on the arguments
45 provided. One nasty detail is that some arithmetic promotions most be done for
46 use by the tgmath.h stuff, but it would be nice to be able to handle vectors
47 etc as well without huge globs of macros. With the above scheme, you could
50 #define sin(x) __builtin_overload(1, x, sin, sinf, sinl, csin, csinf,csinl)(x)
52 and not need to keep track of which argument to "__generic" corresponds to which
55 //===---------------------------------------------------------------------===//
57 To time GCC preprocessing speed without output, use:
59 This is similar to -Eonly.
62 //===---------------------------------------------------------------------===//
64 C++ Template Instantiation benchmark:
65 http://users.rcn.com/abrahams/instantiation_speed/index.html
67 //===---------------------------------------------------------------------===//
69 TODO: File Manager Speedup:
71 We currently do a lot of stat'ing for files that don't exist, particularly
72 when lots of -I paths exist (e.g. see the <iostream> example, check for
73 failures in stat in FileManager::getFile). It would be far better to make
74 the following changes:
75 1. FileEntry contains a sys::Path instead of a std::string for Name.
76 2. sys::Path contains timestamp and size, lazily computed. Eliminate from
78 3. File UIDs are created on request, not when files are opened.
79 These changes make it possible to efficiently have FileEntry objects for
80 files that exist on the file system, but have not been used yet.
83 1. DirectoryEntry gets a boolean value "has read entries". When false, not
84 all entries in the directory are in the file mgr, when true, they are.
85 2. Instead of stat'ing the file in FileManager::getFile, check to see if
86 the dir has been read. If so, fail immediately, if not, read the dir,
88 3. Reading the dir uses the getdirentries syscall, creating an FileEntry
91 //===---------------------------------------------------------------------===//
95 * Get frameworks that don't use #import to do so, e.g.
96 DirectoryService, AudioToolbox, CoreFoundation, etc. Why not using #import?
97 Because they work in C mode? C has #import.
98 * Have the lexer return a token for #import instead of handling it itself.
99 - Create a new preprocessor object with no external state (no -D/U options
100 from the command line, etc). Alternatively, keep track of exactly which
101 external state is used by a #import: declare it somehow.
102 * When having reading a #import file, keep track of whether we have (and/or
103 which) seen any "configuration" macros. Various cases:
104 - Uses of target args (__POWERPC__, __i386): Header has to be parsed
105 multiple times, per-target. What about #ifndef checks? How do we know?
106 - "Configuration" preprocessor macros not defined: POWERPC, etc. What about
107 things like __STDC__ etc? What is and what isn't allowed.
108 * Special handling for "umbrella" headers, which just contain #import stmts:
109 - Cocoa.h/AppKit.h - Contain pointers to digests instead of entire digests
110 themselves? Foundation.h isn't pure umbrella!
111 * Frameworks digests:
112 - Can put "digest" of a framework-worth of headers into the framework
113 itself. To open AppKit, just mmap
114 /System/Library/Frameworks/AppKit.framework/"digest", which provides a
115 symbol table in a well defined format. Lazily unstream stuff that is
116 needed. Contains declarations, macros, and debug information.
117 - System frameworks ship with digests. How do we handle configuration
118 information? How do we handle stuff like:
119 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2
120 which guards a bunch of decls? Should there be a couple of default
121 configs, then have the UI fall back to building/caching its own?
122 - GUI automatically builds digests when UI is idle, both of system
123 frameworks if they aren't not available in the right config, and of app
125 - GUI builds dependence graph of frameworks/digests based on #imports. If a
126 digest is out date, dependent digests are automatically invalidated.
128 * New constraints on #import for objc-v3:
129 - #imported file must not define non-inline function bodies.
130 - Alternatively, they can, and these bodies get compiled/linked *once*
131 per app into a dylib. What about building user dylibs?
132 - Restrictions on ObjC grammar: can't #import the body of a for stmt or fn.
133 - Compiler must detect and reject these cases.
134 - #defines defined within a #import have two behaviors:
135 - By default, they escape the header. These macros *cannot* be #undef'd
136 by other code: this is enforced by the front-end.
137 - Optionally, user can specify what macros escape (whitelist) or can use
140 //===---------------------------------------------------------------------===//
142 TODO: New language feature: Configuration queries:
143 - Instead of #ifdef __POWERPC__, use "if (strcmp(`cpu`, __POWERPC__))", or
144 some other, better, syntax.
145 - Use it to increase the number of "architecture-clean" #import'd files,
146 allowing a single index to be used for all fat slices.
148 //===---------------------------------------------------------------------===//
149 // Specifying targets: -triple and -arch
150 ===---------------------------------------------------------------------===//
152 The clang supports "-triple" and "-arch" options. At most one -triple option may
153 be specified, while multiple -arch options can be specified. Both are optional.
155 The "selection of target" behavior is defined as follows:
157 (1) If the user does not specify -triple:
159 (a) If no -arch options are specified, the target triple used is the host
160 triple (in llvm/Config/config.h).
162 (b) If one or more -arch's are specified (and no -triple), then there is
163 one triple for each -arch, where the specified arch is substituted
164 for the arch in the host triple. Example:
166 host triple = i686-apple-darwin9
167 command: clang -arch ppc -arch ppc64 ...
168 triples used: ppc-apple-darwin9 ppc64-apple-darwin9
170 (2) The user does specify a -triple (only one allowed):
172 (a) If no -arch options are specified, the triple specified by -triple
173 is used. E.g clang -triple i686-apple-darwin9
175 (b) If one or more -arch options are specified, then the triple specified
176 by -triple is used as the primary target, and the arch's specified
177 by -arch are used to create secondary targets. For example:
179 clang -triple i686-apple-darwin9 -arch ppc -arch ppc64
181 has the following targets:
183 i686-apple-darwin9 (primary target)
184 ppc-apple-darwin9 (secondary target)
185 ppc64-apple-darwin9 (secondary target)
187 The secondary targets are used in the 'portability' model (see below).
189 //===---------------------------------------------------------------------===//
191 The 'portability' model in clang is sufficient to catch translation units (or
192 their parts) that are not portable, but it doesn't help if the system headers
193 are non-portable and not fixed. An alternative model that would be easy to use
194 is a 'tainting' scheme. Consider:
197 OSHostByteOrder(void) {
198 #if defined(__LITTLE_ENDIAN__)
199 return OSLittleEndian;
200 #elif defined(__BIG_ENDIAN__)
203 return OSUnknownByteOrder;
207 It would be trivial to mark 'OSHostByteOrder' as being non-portable (tainted)
208 instead of marking the entire translation unit. Then, if OSHostByteOrder is
209 never called/used by the current translation unit, the t-u wouldn't be marked
210 non-portable. However, there is no good way to handle stuff like:
218 int bar() { return X; }
220 When compiling for powerpc, the #define is skipped, so it doesn't know that bar
221 uses a #define that is set on some other target. In practice, limited cases
222 could be handled by scanning the skipped region of a #if, but the fully general
223 case cannot be implemented efficiently. In this case, for example, the #define
224 in the protected region could be turned into either a #define_target or
225 #define_other_target as appropriate. The harder case is code like this (from
228 #if (defined(__ppc__) || defined(__ppc64__))
229 #include <libkern/ppc/OSByteOrder.h>
230 #elif (defined(__i386__) || defined(__x86_64__))
231 #include <libkern/i386/OSByteOrder.h>
233 #include <libkern/machine/OSByteOrder.h>
236 The realistic way to fix this is by having an initial #ifdef __llvm__ that
237 defines its contents in terms of the llvm bswap intrinsics. Other things should
238 be handled on a case-by-case basis.
241 We probably have to do something smarter like this in the future. The C++ header
242 <limits> contains a lot of code like this:
244 static const int digits10 = __LDBL_DIG__;
245 static const int min_exponent = __LDBL_MIN_EXP__;
246 static const int min_exponent10 = __LDBL_MIN_10_EXP__;
247 static const float_denorm_style has_denorm
248 = bool(__LDBL_DENORM_MIN__) ? denorm_present : denorm_absent;
250 ... since this isn't being used in an #ifdef, it should be easy enough to taint
251 the decl for these ivars.
254 /usr/include/sys/cdefs.h contains stuff like this:
257 # if defined(__LDBL_MANT_DIG__) && defined(__DBL_MANT_DIG__) && \
258 __LDBL_MANT_DIG__ > __DBL_MANT_DIG__
259 # if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1040
260 # define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBLStub")
262 # define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBL128")
264 # define __DARWIN_LDBL_COMPAT2(x) __asm("_" __STRING(x) "$LDBL128")
265 # define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
267 # define __DARWIN_LDBL_COMPAT(x) /* nothing */
268 # define __DARWIN_LDBL_COMPAT2(x) /* nothing */
269 # define __DARWIN_LONG_DOUBLE_IS_DOUBLE 1
271 #elif defined(__i386__) || defined(__ppc64__) || defined(__x86_64__)
272 # define __DARWIN_LDBL_COMPAT(x) /* nothing */
273 # define __DARWIN_LDBL_COMPAT2(x) /* nothing */
274 # define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
276 # error Unknown architecture
279 An ideal way to solve this issue is to mark __DARWIN_LDBL_COMPAT /
280 __DARWIN_LDBL_COMPAT2 / __DARWIN_LONG_DOUBLE_IS_DOUBLE as being non-portable
281 because they depend on non-portable macros. In practice though, this may end
282 up being a serious problem: every use of printf will mark the translation unit
283 non-portable if targetting ppc32 and something else.
285 //===---------------------------------------------------------------------===//