blob: baa2edd8d8602a7beaf92dc31b517b317729721f [file] [log] [blame]
Chris Lattner58360332006-10-14 19:53:48 +00001//===---------------------------------------------------------------------===//
2// Random Notes
3//===---------------------------------------------------------------------===//
4
Chris Lattner58360332006-10-14 19:53:48 +00005//===---------------------------------------------------------------------===//
6Extensions:
7
8 * "#define_target X Y"
9 This preprocessor directive works exactly the same was as #define, but it
10 notes that 'X' is a target-specific preprocessor directive. When used, a
11 diagnostic is emitted indicating that the translation unit is non-portable.
12
13 If a target-define is #undef'd before use, no diagnostic is emitted. If 'X'
14 were previously a normal #define macro, the macro is tainted. If 'X' is
15 subsequently #defined as a non-target-specific define, the taint bit is
16 cleared.
17
18 * "#define_other_target X"
19 The preprocessor directive takes a single identifier argument. It notes
20 that this identifier is a target-specific #define for some target other than
21 the current one. Use of this identifier will result in a diagnostic.
22
23 If 'X' is later #undef'd or #define'd, the taint bit is cleared. If 'X' is
24 already defined, X is marked as a target-specific define.
Chris Lattnerecc6fc52006-07-04 19:29:50 +000025
Chris Lattnerbfe98602006-10-14 17:39:56 +000026//===---------------------------------------------------------------------===//
Chris Lattnerecc6fc52006-07-04 19:29:50 +000027
28To time GCC preprocessing speed without output, use:
Chris Lattnerecbf7b42006-07-05 00:08:00 +000029 "time gcc -MM file"
Chris Lattnerbfe98602006-10-14 17:39:56 +000030This is similar to -Eonly.
31
32//===---------------------------------------------------------------------===//
Chris Lattnerdb878cd2006-07-10 06:34:50 +000033
Chris Lattnerf78e6032006-11-05 17:54:43 +000034TODO: File Manager Speedup:
Chris Lattnerdb878cd2006-07-10 06:34:50 +000035
Chris Lattnerf78e6032006-11-05 17:54:43 +000036 We currently do a lot of stat'ing for files that don't exist, particularly
37 when lots of -I paths exist (e.g. see the <iostream> example, check for
38 failures in stat in FileManager::getFile). It would be far better to make
39 the following changes:
40 1. FileEntry contains a sys::Path instead of a std::string for Name.
41 2. sys::Path contains timestamp and size, lazily computed. Eliminate from
42 FileEntry.
43 3. File UIDs are created on request, not when files are opened.
44 These changes make it possible to efficiently have FileEntry objects for
45 files that exist on the file system, but have not been used yet.
46
47 Once this is done:
48 1. DirectoryEntry gets a boolean value "has read entries". When false, not
49 all entries in the directory are in the file mgr, when true, they are.
50 2. Instead of stat'ing the file in FileManager::getFile, check to see if
51 the dir has been read. If so, fail immediately, if not, read the dir,
52 then retry.
53 3. Reading the dir uses the getdirentries syscall, creating an FileEntry
54 for all files found.
55
56//===---------------------------------------------------------------------===//
57
58TODO: Fast #Import:
59
60 * Get frameworks that don't use #import to do so, e.g.
61 DirectoryService, AudioToolbox, CoreFoundation, etc. Why not using #import?
62 Because they work in C mode? C has #import.
63 * Have the lexer return a token for #import instead of handling it itself.
64 - Create a new preprocessor object with no external state (no -D/U options
65 from the command line, etc). Alternatively, keep track of exactly which
66 external state is used by a #import: declare it somehow.
67 * When having reading a #import file, keep track of whether we have (and/or
68 which) seen any "configuration" macros. Various cases:
69 - Uses of target args (__POWERPC__, __i386): Header has to be parsed
70 multiple times, per-target. What about #ifndef checks? How do we know?
71 - "Configuration" preprocessor macros not defined: POWERPC, etc. What about
72 things like __STDC__ etc? What is and what isn't allowed.
73 * Special handling for "umbrella" headers, which just contain #import stmts:
74 - Cocoa.h/AppKit.h - Contain pointers to digests instead of entire digests
75 themselves? Foundation.h isn't pure umbrella!
76 * Frameworks digests:
77 - Can put "digest" of a framework-worth of headers into the framework
78 itself. To open AppKit, just mmap
79 /System/Library/Frameworks/AppKit.framework/"digest", which provides a
80 symbol table in a well defined format. Lazily unstream stuff that is
81 needed. Contains declarations, macros, and debug information.
82 - System frameworks ship with digests. How do we handle configuration
83 information? How do we handle stuff like:
84 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2
85 which guards a bunch of decls? Should there be a couple of default
86 configs, then have the UI fall back to building/caching its own?
87 - GUI automatically builds digests when UI is idle, both of system
88 frameworks if they aren't not available in the right config, and of app
89 frameworks.
90 - GUI builds dependence graph of frameworks/digests based on #imports. If a
91 digest is out date, dependent digests are automatically invalidated.
92
93 * New constraints on #import for objc-v3:
94 - #imported file must not define non-inline function bodies.
95 - Alternatively, they can, and these bodies get compiled/linked *once*
96 per app into a dylib. What about building user dylibs?
97 - Restrictions on ObjC grammar: can't #import the body of a for stmt or fn.
98 - Compiler must detect and reject these cases.
99 - #defines defined within a #import have two behaviors:
100 - By default, they escape the header. These macros *cannot* be #undef'd
101 by other code: this is enforced by the front-end.
102 - Optionally, user can specify what macros escape (whitelist) or can use
103 #undef.
104
105//===---------------------------------------------------------------------===//
106
107TODO: New language feature: Configuration queries:
108 - Instead of #ifdef __POWERPC__, use "if (strcmp(`cpu`, __POWERPC__))", or
109 some other, better, syntax.
110 - Use it to increase the number of "architecture-clean" #import'd files,
111 allowing a single index to be used for all fat slices.
112
Chris Lattnerbfe98602006-10-14 17:39:56 +0000113//===---------------------------------------------------------------------===//
114
115The 'portability' model in clang is sufficient to catch translation units (or
116their parts) that are not portable, but it doesn't help if the system headers
117are non-portable and not fixed. An alternative model that would be easy to use
118is a 'tainting' scheme. Consider:
119
Chris Lattnerdad3c452006-10-15 01:13:14 +0000120int32_t
121OSHostByteOrder(void) {
122#if defined(__LITTLE_ENDIAN__)
123 return OSLittleEndian;
124#elif defined(__BIG_ENDIAN__)
125 return OSBigEndian;
Chris Lattnerbfe98602006-10-14 17:39:56 +0000126#else
Chris Lattnerdad3c452006-10-15 01:13:14 +0000127 return OSUnknownByteOrder;
Chris Lattnerbfe98602006-10-14 17:39:56 +0000128#endif
129}
130
Chris Lattnerdad3c452006-10-15 01:13:14 +0000131It would be trivial to mark 'OSHostByteOrder' as being non-portable (tainted)
132instead of marking the entire translation unit. Then, if OSHostByteOrder is
133never called/used by the current translation unit, the t-u wouldn't be marked
134non-portable. However, there is no good way to handle stuff like:
Chris Lattnerbfe98602006-10-14 17:39:56 +0000135
136extern int X, Y;
137
138#ifndef __POWERPC__
139#define X Y
140#endif
141
142int bar() { return X; }
143
144When compiling for powerpc, the #define is skipped, so it doesn't know that bar
145uses a #define that is set on some other target. In practice, limited cases
146could be handled by scanning the skipped region of a #if, but the fully general
Chris Lattner4856a422006-10-15 22:34:29 +0000147case cannot be implemented efficiently. In this case, for example, the #define
148in the protected region could be turned into either a #define_target or
149#define_other_target as appropriate. The harder case is code like this (from
Chris Lattnerdad3c452006-10-15 01:13:14 +0000150OSByteOrder.h):
Chris Lattnerbfe98602006-10-14 17:39:56 +0000151
Chris Lattnerdad3c452006-10-15 01:13:14 +0000152 #if (defined(__ppc__) || defined(__ppc64__))
153 #include <libkern/ppc/OSByteOrder.h>
154 #elif (defined(__i386__) || defined(__x86_64__))
155 #include <libkern/i386/OSByteOrder.h>
156 #else
157 #include <libkern/machine/OSByteOrder.h>
158 #endif
159
Chris Lattner4856a422006-10-15 22:34:29 +0000160The realistic way to fix this is by having an initial #ifdef __llvm__ that
161defines its contents in terms of the llvm bswap intrinsics. Other things should
162be handled on a case-by-case basis.
Chris Lattnerdad3c452006-10-15 01:13:14 +0000163
164
165We probably have to do something smarter like this in the future. The C++ header
Chris Lattner2ddda732006-10-15 01:05:06 +0000166<limits> contains a lot of code like this:
Chris Lattnerdad3c452006-10-15 01:13:14 +0000167
Chris Lattner2ddda732006-10-15 01:05:06 +0000168 static const int digits10 = __LDBL_DIG__;
169 static const int min_exponent = __LDBL_MIN_EXP__;
170 static const int min_exponent10 = __LDBL_MIN_10_EXP__;
171 static const float_denorm_style has_denorm
172 = bool(__LDBL_DENORM_MIN__) ? denorm_present : denorm_absent;
Chris Lattnerdad3c452006-10-15 01:13:14 +0000173
Chris Lattner2ddda732006-10-15 01:05:06 +0000174 ... since this isn't being used in an #ifdef, it should be easy enough to taint
175the decl for these ivars.
176
177
Chris Lattnerdad3c452006-10-15 01:13:14 +0000178/usr/include/sys/cdefs.h contains stuff like this:
179
180#if defined(__ppc__)
181# if defined(__LDBL_MANT_DIG__) && defined(__DBL_MANT_DIG__) && \
182 __LDBL_MANT_DIG__ > __DBL_MANT_DIG__
183# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1040
184# define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBLStub")
185# else
186# define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBL128")
187# endif
188# define __DARWIN_LDBL_COMPAT2(x) __asm("_" __STRING(x) "$LDBL128")
189# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
190# else
191# define __DARWIN_LDBL_COMPAT(x) /* nothing */
192# define __DARWIN_LDBL_COMPAT2(x) /* nothing */
193# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 1
194# endif
195#elif defined(__i386__) || defined(__ppc64__) || defined(__x86_64__)
196# define __DARWIN_LDBL_COMPAT(x) /* nothing */
197# define __DARWIN_LDBL_COMPAT2(x) /* nothing */
198# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
199#else
200# error Unknown architecture
201#endif
202
203An ideal way to solve this issue is to mark __DARWIN_LDBL_COMPAT /
204__DARWIN_LDBL_COMPAT2 / __DARWIN_LONG_DOUBLE_IS_DOUBLE as being non-portable
Chris Lattner4856a422006-10-15 22:34:29 +0000205because they depend on non-portable macros. In practice though, this may end
206up being a serious problem: every use of printf will mark the translation unit
207non-portable if targetting ppc32 and something else.
Chris Lattner2ddda732006-10-15 01:05:06 +0000208
Chris Lattnerbfe98602006-10-14 17:39:56 +0000209//===---------------------------------------------------------------------===//