]> granicus.if.org Git - clang/commitdiff
[clang] Disable Unicode in asm files
authorVinicius Tinti <viniciustinti@gmail.com>
Fri, 20 Nov 2015 23:42:39 +0000 (23:42 +0000)
committerVinicius Tinti <viniciustinti@gmail.com>
Fri, 20 Nov 2015 23:42:39 +0000 (23:42 +0000)
Clang should not convert tokens to Unicode when preprocessing assembly
files.

Fixes PR25558.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253738 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp
test/CodeGen/asm-unicode.S [new file with mode: 0644]
test/CodeGen/c-unicode.c [new file with mode: 0644]

index cc22ee9dbd810c76d54efbf0b09049e37ff0f5fa..4872dee82456f4f7f2250c0d5f327a43f4521458 100644 (file)
@@ -1354,7 +1354,9 @@ void Lexer::SkipBytes(unsigned Bytes, bool StartOfLine) {
 }
 
 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, const LangOptions &LangOpts) {
 
 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);
diff --git a/test/CodeGen/asm-unicode.S b/test/CodeGen/asm-unicode.S
new file mode 100644 (file)
index 0000000..f4edbe9
--- /dev/null
@@ -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
diff --git a/test/CodeGen/c-unicode.c b/test/CodeGen/c-unicode.c
new file mode 100644 (file)
index 0000000..e9aba55
--- /dev/null
@@ -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 '('