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 To time GCC preprocessing speed without output, use:
33 This is similar to -Eonly.
36 //===---------------------------------------------------------------------===//
38 C++ Template Instantiation benchmark:
39 http://users.rcn.com/abrahams/instantiation_speed/index.html
41 //===---------------------------------------------------------------------===//
43 TODO: File Manager Speedup:
45 We currently do a lot of stat'ing for files that don't exist, particularly
46 when lots of -I paths exist (e.g. see the <iostream> example, check for
47 failures in stat in FileManager::getFile). It would be far better to make
48 the following changes:
49 1. FileEntry contains a sys::Path instead of a std::string for Name.
50 2. sys::Path contains timestamp and size, lazily computed. Eliminate from
52 3. File UIDs are created on request, not when files are opened.
53 These changes make it possible to efficiently have FileEntry objects for
54 files that exist on the file system, but have not been used yet.
57 1. DirectoryEntry gets a boolean value "has read entries". When false, not
58 all entries in the directory are in the file mgr, when true, they are.
59 2. Instead of stat'ing the file in FileManager::getFile, check to see if
60 the dir has been read. If so, fail immediately, if not, read the dir,
62 3. Reading the dir uses the getdirentries syscall, creating an FileEntry
65 //===---------------------------------------------------------------------===//
69 * Get frameworks that don't use #import to do so, e.g.
70 DirectoryService, AudioToolbox, CoreFoundation, etc. Why not using #import?
71 Because they work in C mode? C has #import.
72 * Have the lexer return a token for #import instead of handling it itself.
73 - Create a new preprocessor object with no external state (no -D/U options
74 from the command line, etc). Alternatively, keep track of exactly which
75 external state is used by a #import: declare it somehow.
76 * When having reading a #import file, keep track of whether we have (and/or
77 which) seen any "configuration" macros. Various cases:
78 - Uses of target args (__POWERPC__, __i386): Header has to be parsed
79 multiple times, per-target. What about #ifndef checks? How do we know?
80 - "Configuration" preprocessor macros not defined: POWERPC, etc. What about
81 things like __STDC__ etc? What is and what isn't allowed.
82 * Special handling for "umbrella" headers, which just contain #import stmts:
83 - Cocoa.h/AppKit.h - Contain pointers to digests instead of entire digests
84 themselves? Foundation.h isn't pure umbrella!
86 - Can put "digest" of a framework-worth of headers into the framework
87 itself. To open AppKit, just mmap
88 /System/Library/Frameworks/AppKit.framework/"digest", which provides a
89 symbol table in a well defined format. Lazily unstream stuff that is
90 needed. Contains declarations, macros, and debug information.
91 - System frameworks ship with digests. How do we handle configuration
92 information? How do we handle stuff like:
93 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2
94 which guards a bunch of decls? Should there be a couple of default
95 configs, then have the UI fall back to building/caching its own?
96 - GUI automatically builds digests when UI is idle, both of system
97 frameworks if they aren't not available in the right config, and of app
99 - GUI builds dependence graph of frameworks/digests based on #imports. If a
100 digest is out date, dependent digests are automatically invalidated.
102 * New constraints on #import for objc-v3:
103 - #imported file must not define non-inline function bodies.
104 - Alternatively, they can, and these bodies get compiled/linked *once*
105 per app into a dylib. What about building user dylibs?
106 - Restrictions on ObjC grammar: can't #import the body of a for stmt or fn.
107 - Compiler must detect and reject these cases.
108 - #defines defined within a #import have two behaviors:
109 - By default, they escape the header. These macros *cannot* be #undef'd
110 by other code: this is enforced by the front-end.
111 - Optionally, user can specify what macros escape (whitelist) or can use
114 //===---------------------------------------------------------------------===//
116 TODO: New language feature: Configuration queries:
117 - Instead of #ifdef __POWERPC__, use "if (strcmp(`cpu`, __POWERPC__))", or
118 some other, better, syntax.
119 - Use it to increase the number of "architecture-clean" #import'd files,
120 allowing a single index to be used for all fat slices.
122 //===---------------------------------------------------------------------===//
123 // Specifying targets: -triple and -arch
124 ===---------------------------------------------------------------------===//
126 The clang supports "-triple" and "-arch" options. At most one -triple option may
127 be specified, while multiple -arch options can be specified. Both are optional.
129 The "selection of target" behavior is defined as follows:
131 (1) If the user does not specify -triple:
133 (a) If no -arch options are specified, the target triple used is the host
134 triple (in llvm/Config/config.h).
136 (b) If one or more -arch's are specified (and no -triple), then there is
137 one triple for each -arch, where the specified arch is substituted
138 for the arch in the host triple. Example:
140 host triple = i686-apple-darwin9
141 command: clang -arch ppc -arch ppc64 ...
142 triples used: ppc-apple-darwin9 ppc64-apple-darwin9
144 (2) The user does specify a -triple (only one allowed):
146 (a) If no -arch options are specified, the triple specified by -triple
147 is used. E.g clang -triple i686-apple-darwin9
149 (b) If one or more -arch options are specified, then the triple specified
150 by -triple is used as the primary target, and the arch's specified
151 by -arch are used to create secondary targets. For example:
153 clang -triple i686-apple-darwin9 -arch ppc -arch ppc64
155 has the following targets:
157 i686-apple-darwin9 (primary target)
158 ppc-apple-darwin9 (secondary target)
159 ppc64-apple-darwin9 (secondary target)
161 The secondary targets are used in the 'portability' model (see below).
163 //===---------------------------------------------------------------------===//
165 The 'portability' model in clang is sufficient to catch translation units (or
166 their parts) that are not portable, but it doesn't help if the system headers
167 are non-portable and not fixed. An alternative model that would be easy to use
168 is a 'tainting' scheme. Consider:
171 OSHostByteOrder(void) {
172 #if defined(__LITTLE_ENDIAN__)
173 return OSLittleEndian;
174 #elif defined(__BIG_ENDIAN__)
177 return OSUnknownByteOrder;
181 It would be trivial to mark 'OSHostByteOrder' as being non-portable (tainted)
182 instead of marking the entire translation unit. Then, if OSHostByteOrder is
183 never called/used by the current translation unit, the t-u wouldn't be marked
184 non-portable. However, there is no good way to handle stuff like:
192 int bar() { return X; }
194 When compiling for powerpc, the #define is skipped, so it doesn't know that bar
195 uses a #define that is set on some other target. In practice, limited cases
196 could be handled by scanning the skipped region of a #if, but the fully general
197 case cannot be implemented efficiently. In this case, for example, the #define
198 in the protected region could be turned into either a #define_target or
199 #define_other_target as appropriate. The harder case is code like this (from
202 #if (defined(__ppc__) || defined(__ppc64__))
203 #include <libkern/ppc/OSByteOrder.h>
204 #elif (defined(__i386__) || defined(__x86_64__))
205 #include <libkern/i386/OSByteOrder.h>
207 #include <libkern/machine/OSByteOrder.h>
210 The realistic way to fix this is by having an initial #ifdef __llvm__ that
211 defines its contents in terms of the llvm bswap intrinsics. Other things should
212 be handled on a case-by-case basis.
215 We probably have to do something smarter like this in the future. The C++ header
216 <limits> contains a lot of code like this:
218 static const int digits10 = __LDBL_DIG__;
219 static const int min_exponent = __LDBL_MIN_EXP__;
220 static const int min_exponent10 = __LDBL_MIN_10_EXP__;
221 static const float_denorm_style has_denorm
222 = bool(__LDBL_DENORM_MIN__) ? denorm_present : denorm_absent;
224 ... since this isn't being used in an #ifdef, it should be easy enough to taint
225 the decl for these ivars.
228 /usr/include/sys/cdefs.h contains stuff like this:
231 # if defined(__LDBL_MANT_DIG__) && defined(__DBL_MANT_DIG__) && \
232 __LDBL_MANT_DIG__ > __DBL_MANT_DIG__
233 # if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1040
234 # define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBLStub")
236 # define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBL128")
238 # define __DARWIN_LDBL_COMPAT2(x) __asm("_" __STRING(x) "$LDBL128")
239 # define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
241 # define __DARWIN_LDBL_COMPAT(x) /* nothing */
242 # define __DARWIN_LDBL_COMPAT2(x) /* nothing */
243 # define __DARWIN_LONG_DOUBLE_IS_DOUBLE 1
245 #elif defined(__i386__) || defined(__ppc64__) || defined(__x86_64__)
246 # define __DARWIN_LDBL_COMPAT(x) /* nothing */
247 # define __DARWIN_LDBL_COMPAT2(x) /* nothing */
248 # define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
250 # error Unknown architecture
253 An ideal way to solve this issue is to mark __DARWIN_LDBL_COMPAT /
254 __DARWIN_LDBL_COMPAT2 / __DARWIN_LONG_DOUBLE_IS_DOUBLE as being non-portable
255 because they depend on non-portable macros. In practice though, this may end
256 up being a serious problem: every use of printf will mark the translation unit
257 non-portable if targetting ppc32 and something else.
259 //===---------------------------------------------------------------------===//