r253738 - [clang] Disable Unicode in asm files

Vinicius Tinti via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 20 15:42:39 PST 2015


Author: tinti
Date: Fri Nov 20 17:42:39 2015
New Revision: 253738

URL: http://llvm.org/viewvc/llvm-project?rev=253738&view=rev
Log:
[clang] Disable Unicode in asm files

Clang should not convert tokens to Unicode when preprocessing assembly
files.

Fixes PR25558.

Added:
    cfe/trunk/test/CodeGen/asm-unicode.S
    cfe/trunk/test/CodeGen/c-unicode.c
Modified:
    cfe/trunk/lib/Lex/Lexer.cpp

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=253738&r1=253737&r2=253738&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Nov 20 17:42:39 2015
@@ -1354,7 +1354,9 @@ void Lexer::SkipBytes(unsigned Bytes, bo
 }
 
 static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
-  if (LangOpts.CPlusPlus11 || LangOpts.C11) {
+  if (LangOpts.AsmPreprocessor) {
+    return false;
+  } else if (LangOpts.CPlusPlus11 || LangOpts.C11) {
     static const llvm::sys::UnicodeCharSet C11AllowedIDChars(
         C11AllowedIDCharRanges);
     return C11AllowedIDChars.contains(C);
@@ -1371,7 +1373,9 @@ static bool isAllowedIDChar(uint32_t C,
 
 static bool isAllowedInitiallyIDChar(uint32_t C, const LangOptions &LangOpts) {
   assert(isAllowedIDChar(C, LangOpts));
-  if (LangOpts.CPlusPlus11 || LangOpts.C11) {
+  if (LangOpts.AsmPreprocessor) {
+    return false;
+  } else if (LangOpts.CPlusPlus11 || LangOpts.C11) {
     static const llvm::sys::UnicodeCharSet C11DisallowedInitialIDChars(
         C11DisallowedInitialIDCharRanges);
     return !C11DisallowedInitialIDChars.contains(C);

Added: cfe/trunk/test/CodeGen/asm-unicode.S
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asm-unicode.S?rev=253738&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/asm-unicode.S (added)
+++ cfe/trunk/test/CodeGen/asm-unicode.S Fri Nov 20 17:42:39 2015
@@ -0,0 +1,12 @@
+// RUN: %clang -S %s -o - | FileCheck %s
+.macro  my_macro, trace=1, uaccess=1
+.if \uaccess
+// CHECK: .if \uaccess
+// CHECK-NOT: .if 곎ss
+// CHECK: my_macro trace=1
+        my_macro trace=1
+.endif
+.endm
+
+foo:
+        my_macro trace=0

Added: cfe/trunk/test/CodeGen/c-unicode.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/c-unicode.c?rev=253738&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/c-unicode.c (added)
+++ cfe/trunk/test/CodeGen/c-unicode.c Fri Nov 20 17:42:39 2015
@@ -0,0 +1,7 @@
+// RUN: %clang -S %s -o - | FileCheck %s -check-prefix=ALLOWED
+// RUN: not %clang -std=c89 -S %s -o - 2>&1 | FileCheck %s -check-prefix=DENIED
+int \uaccess = 0;
+// ALLOWED: "곎ss":
+// ALLOWED-NOT: "\uaccess":
+// DENIED: warning: universal character names are only valid in C99 or C++; treating as '\' followed by identifier [-Wunicode]
+// DENIED: error: expected identifier or '('




More information about the cfe-commits mailing list