[flang-commits] [flang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #67592)

Aaron Ballman via flang-commits flang-commits at lists.llvm.org
Mon Oct 2 08:58:38 PDT 2023


================
@@ -2218,6 +2219,24 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
     } else {
       if (!FirstArg)
         OS << Comma;
+
+      if (Policy.UseClassForTemplateArgument &&
+          Argument.getKind() == TemplateArgument::Type &&
+          !Argument.getAsType()->isBuiltinType()) {
+        const Type *Ty = Argument.getAsType().getTypePtr();
+        const char *kw;
+        if (Ty->isStructureType())
+          kw = "struct ";
+        else if (Ty->isClassType())
+          kw = "class ";
+        else if (Ty->isUnionType())
+          kw = "union ";
+        else if (Ty->isEnumeralType())
+          kw = "enum ";
+        else
+          llvm_unreachable("argument type not expected");
----------------
AaronBallman wrote:

This sure seems reachable to me! Consider:
```
template <class T>
class TestClass {
public:
   TestClass() {
      constexpr const char *function = __FUNCTION__;
      constexpr const char *func = __func__;
      puts(function);
      puts(func);
   }
};

class S {};
}

void instantiate() {
  test_func::TestClass<test_func::S *>{};
}
```
which I believe will crash.

https://github.com/llvm/llvm-project/pull/67592


More information about the flang-commits mailing list