From 935a70c1e76d78985f20d422940280161b941299 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 30 Jun 2011 20:17:41 +0000 Subject: [PATCH] Fix off-by-one error in StringLiteral::getLocationOfByte. This fixes PR10223. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134183 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 2 +- test/Sema/asm.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index fdcb77f324..1d0319f601 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -593,7 +593,7 @@ getLocationOfByte(unsigned ByteNo, const SourceManager &SM, // If the byte is in this token, return the location of the byte. if (ByteNo < TokNumBytes || - (ByteNo == TokNumBytes && TokNo == getNumConcatenated())) { + (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); // Now that we know the offset of the token in the spelling, use the diff --git a/test/Sema/asm.c b/test/Sema/asm.c index a3313cad2b..f1c24c8fb6 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -117,3 +117,9 @@ void test11(void) { void test12(void) { register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}} } + +// PR10223 +void test13(void) { + void *esp; + __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}} +} -- 2.40.0