summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-03-08 07:59:04 +0000
committerJohn McCall <rjmccall@apple.com>2011-03-08 07:59:04 +0000
commit462c055d85ffcea5bec6dfc4f547fe38aedea848 (patch)
treed18804c0ddfab9fc731e80be2a034b0fe37d6dc9 /clang/lib/Sema
parentafc8098c9e9da8f315b2d79f04fbc12a765e0dcb (diff)
downloadbcm5719-llvm-462c055d85ffcea5bec6dfc4f547fe38aedea848.tar.gz
bcm5719-llvm-462c055d85ffcea5bec6dfc4f547fe38aedea848.zip
Fix my earlier commit to work with escaped newlines and leave breadcrumbs
in case we want to make a world where we can check intermediate instantiations for this kind of breadcrumb. llvm-svn: 127221
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/Sema.cpp21
-rw-r--r--clang/lib/Sema/SemaExpr.cpp5
-rw-r--r--clang/lib/Sema/SemaType.cpp10
3 files changed, 27 insertions, 9 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 4bfb388081d..0846845e26d 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -592,6 +592,27 @@ Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) {
return Builder;
}
+/// \brief Looks through the macro-instantiation chain for the given
+/// location, looking for a macro instantiation with the given name.
+/// If one is found, returns true and sets the location to that
+/// instantiation loc.
+bool Sema::findMacroSpelling(SourceLocation &locref, llvm::StringRef name) {
+ SourceLocation loc = locref;
+ if (!loc.isMacroID()) return false;
+
+ // There's no good way right now to look at the intermediate
+ // instantiations, so just jump to the instantiation location.
+ loc = getSourceManager().getInstantiationLoc(loc);
+
+ // If that's written with the name, stop here.
+ llvm::SmallVector<char, 16> buffer;
+ if (getPreprocessor().getSpelling(loc, buffer) == name) {
+ locref = loc;
+ return true;
+ }
+ return false;
+}
+
/// \brief Determines the active Scope associated with the given declaration
/// context.
///
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c4218c3365d..8f79428eae1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5261,9 +5261,8 @@ bool Sema::DiagnoseConditionalForNull(Expr *LHS, Expr *RHS,
// In this case, check to make sure that we got here from a "NULL"
// string in the source code.
NullExpr = NullExpr->IgnoreParenImpCasts();
- SourceLocation Loc =
- getSourceManager().getInstantiationLoc(NullExpr->getExprLoc());
- if (getPreprocessor().getSpelling(Loc) != "NULL")
+ SourceLocation loc = NullExpr->getExprLoc();
+ if (!findMacroSpelling(loc, "NULL"))
return false;
}
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 772a5575459..11e7c313829 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -95,12 +95,10 @@ static void diagnoseBadTypeAttribute(Sema &S, const AttributeList &attr,
// The GC attributes are usually written with macros; special-case them.
if (useInstantiationLoc && loc.isMacroID() && attr.getParameterName()) {
- SourceLocation instLoc = S.getSourceManager().getInstantiationLoc(loc);
- llvm::StringRef macro = S.getPreprocessor().getSpelling(instLoc);
- if ((macro == "__strong" && attr.getParameterName()->isStr("strong")) ||
- (macro == "__weak" && attr.getParameterName()->isStr("weak"))) {
- loc = instLoc;
- name = macro;
+ if (attr.getParameterName()->isStr("strong")) {
+ if (S.findMacroSpelling(loc, "__strong")) name = "__strong";
+ } else if (attr.getParameterName()->isStr("weak")) {
+ if (S.findMacroSpelling(loc, "__weak")) name = "__weak";
}
}
OpenPOWER on IntegriCloud