Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/LangStandards.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- LangStandards.cpp - Language Standard Definitions ----------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "clang/Basic/LangStandard.h"
10
#include "clang/Config/config.h"
11
#include "llvm/ADT/StringSwitch.h"
12
#include "llvm/ADT/Triple.h"
13
#include "llvm/Support/ErrorHandling.h"
14
using namespace clang;
15
16
#define LANGSTANDARD(id, name, lang, desc, features)                           \
17
  static const LangStandard Lang_##id = {name, desc, features, Language::lang};
18
#include "clang/Basic/LangStandards.def"
19
20
980k
const LangStandard &LangStandard::getLangStandardForKind(Kind K) {
21
980k
  switch (K) {
22
0
  case lang_unspecified:
23
0
    llvm::report_fatal_error("getLangStandardForKind() on unspecified kind");
24
0
#define LANGSTANDARD(id, name, lang, desc, features) \
25
980k
    case lang_##id: return Lang_##id;
26
980k
#include 
"clang/Basic/LangStandards.def"0
27
980k
  }
28
0
  llvm_unreachable("Invalid language kind!");
29
0
}
30
31
110k
LangStandard::Kind LangStandard::getLangKind(StringRef Name) {
32
110k
  return llvm::StringSwitch<Kind>(Name)
33
4.31M
#define LANGSTANDARD(id, name, lang, desc, features) .Case(name, lang_##id)
34
3.86M
#define LANGSTANDARD_ALIAS(id, alias) .Case(alias, lang_##id)
35
110k
#include "clang/Basic/LangStandards.def"
36
110k
      .Default(lang_unspecified);
37
110k
}
38
39
10
const LangStandard *LangStandard::getLangStandardForName(StringRef Name) {
40
10
  Kind K = getLangKind(Name);
41
10
  if (K == lang_unspecified)
42
0
    return nullptr;
43
44
10
  return &getLangStandardForKind(K);
45
10
}
46
47
LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang,
48
31.7k
                                                     const llvm::Triple &T) {
49
31.7k
  switch (Lang) {
50
0
  case Language::Unknown:
51
0
  case Language::LLVM_IR:
52
0
    llvm_unreachable("Invalid input kind!");
53
374
  case Language::OpenCL:
54
374
    return LangStandard::lang_opencl12;
55
50
  case Language::OpenCLCXX:
56
50
    return LangStandard::lang_openclcpp10;
57
171
  case Language::CUDA:
58
171
    return LangStandard::lang_cuda;
59
43
  case Language::Asm:
60
11.9k
  case Language::C:
61
11.9k
    if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
62
0
      return CLANG_DEFAULT_STD_C;
63
64
    // The PS4 uses C99 as the default C standard.
65
11.9k
    if (T.isPS4())
66
17
      return LangStandard::lang_gnu99;
67
11.9k
    return LangStandard::lang_gnu17;
68
4.10k
  case Language::ObjC:
69
4.10k
    if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
70
0
      return CLANG_DEFAULT_STD_C;
71
72
4.10k
    return LangStandard::lang_gnu11;
73
12.7k
  case Language::CXX:
74
14.9k
  case Language::ObjCXX:
75
14.9k
    if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
76
0
      return CLANG_DEFAULT_STD_CXX;
77
78
14.9k
    if (T.isDriverKit())
79
1
      return LangStandard::lang_gnucxx17;
80
14.9k
    else
81
14.9k
      return LangStandard::lang_gnucxx14;
82
5
  case Language::RenderScript:
83
5
    return LangStandard::lang_c99;
84
103
  case Language::HIP:
85
103
    return LangStandard::lang_hip;
86
40
  case Language::HLSL:
87
40
    return LangStandard::lang_hlsl2021;
88
31.7k
  }
89
0
  llvm_unreachable("unhandled Language kind!");
90
0
}