Index: test/Driver/debug-options.c
===================================================================
--- test/Driver/debug-options.c	(revision 157599)
+++ test/Driver/debug-options.c	(working copy)
@@ -7,8 +7,11 @@
 // RUN: %clang -### -c -ganything %s 2>&1 | FileCheck -check-prefix=GANY %s
 // RUN: %clang -### -c -ggdb %s 2>&1 | FileCheck -check-prefix=GGDB %s
 // RUN: %clang -### -c -gfoo %s 2>&1 | FileCheck -check-prefix=GFOO %s
+// RUN: %clang -### -c -g -g0 %s 2>&1 | FileCheck -check-prefix=GG0 %s
 // RUN: %clang -### -c -gline-tables-only %s 2>&1 \
 // RUN:             | FileCheck -check-prefix=GLTO %s
+// RUN: %clang -### -c -gline-tables-only -g %s 2>&1 \
+// RUN:             | FileCheck -check-prefix=GLTO2 %s
 //
 // G: "-cc1"
 // G: "-g"
@@ -28,5 +31,15 @@
 // GFOO: "-cc1"
 // GFOO-NOT: "-g"
 //
+// GG0: "-cc1"
+// GG0-NOT: "-g"
+//
 // GLTO: "-cc1"
-// GLTO: "-g"
+// GLTO-NOT: "-g"
+// GLTO: "-gline-tables-only"
+// GLTO-NOT: "-g"
+//
+// GLTO2: "-cc1"
+// GLTO2-NOT: "-gline-tables-only"
+// GLTO2: "-g"
+// GLTO2-NOT: "-gline-tables-only"
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 157599)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -1839,15 +1839,17 @@
                       D.CCLogDiagnosticsFilename : "-");
   }
 
-  // Special case debug options to only pass -g to clang. This is
-  // wrong.
+  // Use the last option from "-g" group. "-gline-tables-only" is
+  // preserved, all other debug options are substituted with "-g".
+  // This is wrong.
   Args.ClaimAllArgs(options::OPT_g_Group);
-  if (Arg *A = Args.getLastArg(options::OPT_g_Group))
-    if (!A->getOption().matches(options::OPT_g0)) {
+  if (Arg *A = Args.getLastArg(options::OPT_g_Group)) {
+    if (A->getOption().matches(options::OPT_gline_tables_only)) {
+      CmdArgs.push_back("-gline-tables-only");
+    } else if (!A->getOption().matches(options::OPT_g0)) {
       CmdArgs.push_back("-g");
     }
-  if (Args.hasArg(options::OPT_gline_tables_only))
-    CmdArgs.push_back("-gline-tables-only");
+  }
 
   Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections);
   Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections);
