[cfe-commits] [PATCH] Disassociate pragmas from IdentifierInfos

Douglas Gregor dgregor at apple.com
Tue Jul 13 01:55:57 PDT 2010


On Jul 13, 2010, at 12:57 AM, Argyrios Kyrtzidis wrote:

> The attached patch modifies the pragma handlers to accept and use StringRefs instead of IdentifierInfos.
> 
> When loading the PCH, IdentifierInfos that are associated with pragmas cause declarations that use these identifiers to be deserialized (e.g. the "clang" pragma causes the "clang" namespace to be loaded).
> We can avoid this if we just use StringRefs for the pragmas.
> 
> As a bonus, since we don't have to create and pass IdentifierInfos, the pragma interfaces get a bit more simplified.


Good stuff. My only concern is that it's generally dangerous to hold on to StringRefs like this:

@@ -33,12 +35,13 @@ namespace clang {
 /// we treat "#pragma STDC" and "#pragma GCC" as namespaces that contain other
 /// pragmas.
 class PragmaHandler {
-  const IdentifierInfo *Name;
+  llvm::StringRef Name;

It works when the StrinRef refers to a string literal or some storage that lives longer than the pragma handler, but the latter is a trap waiting for someone. It would be better to either store a std::string in PragmaHandler or to eliminate the Name field altogether.

	- Doug



More information about the cfe-commits mailing list